. Advertisement .
..3..
. Advertisement .
..4..
Computers are mostly used to store information and extract information from it. Python is one of the most powerful programming languages. We can use Python to get computers to do most routine processes. This blog is all about how we can split a String using WhiteSpace in Python.
How Can You Split a String Using WhiteSpace in Python?
In Python, simply utilize split() to split a String by WhiteSpace. You can split a string using white space with split() in Python. It’s a simple method for splitting a string. So, to learn more about this without spending more time, consider the following example:
my_Str = ‘ Hello my love ‘.split()
print(my_Str)
Result:
[‘Hello’, ‘my’, ‘love’]1) Utilize split()
Syntax
|
You can split a string using white space with split() in Python. It’s a simple method for splitting a string. So, to learn more about this without spending more time, consider the following example:
my_Str = ' Hello my love '.split()
print(my_Str)
Result:
['Hello', 'my', 'love']
2) Utilize re.findall
You can split a string using white space with re.findall in Python. It’s a simple method for splitting a string. So, to learn more about this without spending more time, consider the following example:
import re
my_Str = "Hello my\n love\t ITtutoria"
print(re.findall(r'\S+', my_Str))
Result:
['Hello', 'my', 'love', 'ITtutoria']
Conclusion
Splitting a String using WhiteSpace in Python is a confusing problem. We hope this blog has helped clear the air around how to do it. If you have more questions about this topic, please comment below. Thank you for reading; we are always excited when one of our posts can provide useful information on a topic like this!
Leave a comment