How to split string on whitespace in Python?

Sometimes, we want to split string on whitespace in Python.

In this article, we’ll look at how to split string on whitespace in Python.

How to split string on whitespace in Python?

To split string on whitespace in Python, we can use the string split method.

For instance, we write

l =  "many   fancy word nhello    thi".split()

to call split on the "many fancy word nhello thi" string to return a list of the strings that’s split on whitespace.

Conclusion

To split string on whitespace in Python, we can use the string split method.