PYTHON CORE · LESSON 18

Add to the list

Method of append · about 11 minutes

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

The list can be changed.

append adds a new thing to the bottom of the list. The append is given a period.

pets = ["кот"]
pets.append("пёс")
print(pets)

✦ Now there are two pets on the list.

STEP 2

Add one more thing.

Each append call adds exactly one element.

colors = ["синий"]
colors.append("зелёный")
print(len(colors))

✦ Now len will show 2.

IN-CLASS PRACTICE

Type the code yourself

Dial the program. Notice the dot before append.

games = ["мяч"]
games.append("лото")
print(games)
Open the editor for class work
HOMEWORK

Solve it yourself

Create pets with the word «кот». Add «хомяк» through append, and then output the entire list.

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

Opening up your homework