PYTHON CORE · LESSON 17

Length of list

So many things. · about 10 minutes

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

Count the elements.

len counts how many items are on the list. Write the name of the list in brackets.

pets = ["кот", "пёс"]
print(len(pets))

✦ Answer 2.

STEP 2

It also works with text.

len can count not only the elements of the list, but also the letters in the line.

word = "кот"
print(len(word))

✦ The word cat has three letters.

IN-CLASS PRACTICE

Type the code yourself

Reprint the list and show its length.

games = ["шахматы", "мяч", "лото"]
print(len(games))
Open the editor for class work
HOMEWORK

Solve it yourself

Create a list of colors from «красный», «синий», «зелёный», «жёлтый». Specify the number of colors using len.

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

Opening up your homework