Categories
Python Answers

How to split string on whitespace in Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *