← Python from Scratch
Lesson 34 of 78 · 5 XP
Warm-up: how many words warm-up
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
The split() method cuts a string at spaces and returns a list of words. len() of a list is how many items it has:
words = "cat dog mouse".split()
print(words) # ['cat', 'dog', 'mouse']
print(len(words)) # 3
print(words[0]) # cat — counting starts from zero
Task. Read a line of words separated by spaces and print how many words it has.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.