Program to print each word of the given sentence in pyhon | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Program to print each word of the given sentence in pyhon

1st Sep 2017, 3:57 PM
Abhinav Anand
Abhinav Anand - avatar
4 Answers
+ 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.
1st Sep 2017, 4:55 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
1st Sep 2017, 5:00 PM
Ghauth Christians
Ghauth Christians - avatar
+ 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])
1st Sep 2017, 4:03 PM
Ghauth Christians
Ghauth Christians - avatar
+ 3
for word in sentence.split(" "): print(word)
1st Sep 2017, 9:45 PM
David Ashton
David Ashton - avatar