Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to split a String by WhiteSpace in Python. so without wasting time lets learn about of this.
How to split a String by WhiteSpace in Python
split a String by WhiteSpace in Python
to split a String by WhiteSpace in Python just use split(). By using split() you can split a string by white space in python. Its a very easy way to split a string. So lets learn about of this without wasting time by given below example:
mystr = ' Hello guys how are you '.split() print(mystr)
Output :['Hello', 'guys', 'how', 'are', 'you']
How to split a String by WhiteSpace in Python
to split a String by WhiteSpace in Python just use re.split(). By using re.split() you can split a string by white space in python. Its a very easy way to split a string. So lets learn about of this without wasting time by given below example:
import re myStr = "Hello guys\n how\t are you" print(re.findall(r'\S+', myStr))
Output :['Hello', 'guys', 'how', 'are', 'you']
how to split a string in python
To split a String by WhiteSpace in Python just use split(). By using split() you can split a string by white space in python. Its a very easy way to split a string. So lets learn about of this without wasting time by given below example:
mystr = ' Hello guys how are you '.split() print(mystr)
Output :['Hello', 'guys', 'how', 'are', 'you']
Method 1: split a String by WhiteSpace Using split()
By using split() you can split a string by white space in python. Its a very easy way to split a string. So lets learn about of this without wasting time by given below example:
mystr = ' Hello guys how are you '.split()
print(mystr)
Output :
['Hello', 'guys', 'how', 'are', 'you']
Method 2: Use re.split()
By using re.split() you can split a string by white space in python. Its a very easy way to split a string. So lets learn about of this without wasting time by given below example:
import re
myStr = "Hello guys\n how\t are you"
print(re.findall(r'\S+', myStr))
Output :
['Hello', 'guys', 'how', 'are', 'you']
Conclusion
It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read