Home › Python with Chai › Lesson 6

Dictionaries: the chai menu card

Python with Chai, lesson 6 of 20. A short Hinglish video, simple English notes and code you can run, free.

Open the interactive lesson with Run button

The idea

A dictionary stores pairs of keys and values: an item's name and its price.

Give it a key, get the value back: menu["Masala"] gives 20.

Adding an item and changing a price both use menu[key] = value.

The code

menu = {"Masala": 20, "Adrak": 15, "Elaichi": 25}

print(menu["Masala"])
menu["Tulsi"] = 30     # new item
menu["Adrak"] = 18     # price changed
print(menu)

Output:

20
{'Masala': 20, 'Adrak': 18, 'Elaichi': 25, 'Tulsi': 30}

Try it yourself

Remember

A dictionary lets you look things up by name.

← for loops: try every flavour · Mini project: the chai bill →

All lessons: Python with Chai