Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I'm looking for the Python equivalent of

String str = "many fancy word \nhello \thi"; 

String whiteSpaceRegex = "\\s"; 

String[] words = str.split(whiteSpaceRegex); 

Output:-

["many", "fancy", "word", "hello", "hi"]

1 Answer

0 votes
by (106k points)

To split string on whitespaces in Python you can use str.split() method without an argument splits on whitespace:

>>> "many fancy word \nhello \thi".split() 

['many', 'fancy', 'word', 'hello', 'hi']

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 3, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...