PYTHON CORE · LESSON 19

Dictionary

Looking by name. · about 12 minutes

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

Name and meaning

The dictionary stores pairs: name and meaning. The pairs are recorded inside the brackets.

player = {"name": "Лев", "score": 5}

✦ The player has a name and points.

STEP 2

Get it by name.

After the dictionary name, write the key in square brackets. That's how you get his value.

player = {"name": "Лев", "score": 5}
print(player["name"])

✦ A lion will appear.

IN-CLASS PRACTICE

Type the code yourself

Reprint the dictionary and get the key value.

pet = {"name": "Рекс", "age": 3}
print(pet["name"])
Open the editor for class work
HOMEWORK

Solve it yourself

Create a book dictionary with «title» keys: «Космос» and «pages»:20. Find the «title» key value.

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

Opening up your homework