To iterate over words in a string in Python, you can use the split
method with a space as the delimiter.
In this example,
str
with a value of 'Hello World Python'
.split(' ')
method on the string to split it into words based on spaces.str = 'Hello World Python'
words = str.split(' ')
for word in words:
print(word)
Hello World Python
In this tutorial, we learned How to Iterate over Words in String in Python language with well detailed examples.