How can I split a string into a list of words in Python?
How can I split a string into a list of words in Python?
How can I split a string into a list of words in Python?
solveurit24@gmail.com Changed status to publish February 13, 2025
Use the split() method. By default, it splits on whitespace.
s = "Hello world, this is a test."
words = s.split()
print(words) # Output: ['Hello', 'world,', 'this', 'is', 'a', 'test.']
Explanation:
- The
split()method returns a list of substrings separated by whitespace or a specified delimiter.
solveurit24@gmail.com Changed status to publish February 13, 2025