+ 1
Program to print each word of the given sentence in pyhon
4 ответов
+ 4
Just an FYI:
No need to wrap sentence.split() in list() as split() already returns a list.
Also, a space (" ") is the default delimiter for spit, so the use of split(" ") is the same as split().
I'm sure @Gavin is just being explicit to help the understanding of the code.
+ 4
Lol that's correct @ChaoticDawg, this way he'll be curious about what "delimiter" means and hopefully he'll figure out that he can use multiple delimiters as arguments in split.
+ 3
You can put your sentence in a string and then get the words by splitting the string with a whitespace delimiter.
Example (Python):
sentence="Hello World"
words=list(sentence.split(" "))
print(words[0])
print(words[1])
+ 3
for word in sentence.split(" "):
print(word)