PYTHON CORE · LESSON 43

Split the sentence.

Method of split · about 10 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

From line to list

split divides the text into spaces. It makes a list of words.

text = "кот пёс"
print(text.split())
The text becomes a list
Line.пёсsplit()deliteListcat, пёс

✦ The result is a two-word list.

STEP 2

The list can be calculated.

The result of split can be saved. Then len will show you how many words you have.

words = "один два три".split()
print(len(words))

✦ That's 3.

IN-CLASS PRACTICE

Type the code yourself

Type a line and divide it into words.

text = "солнце луна"
print(text.split())
Open the editor for class work
HOMEWORK

Solve it yourself

Save the «кот пёс» text in words. List the words using split.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework