PYTHON LESSON 12 OF 32

Dictionaries: names meet values

A dictionary stores key-value pairs. Think of a contact book where a name points to a phone number. Keys are unique. get() can provide a default when a key is missing.

हिन्दी में समझें

डिक्शनरी कुंजी और मान की जोड़ी रखती है, जैसे नाम से फोन नंबर ढूँढना। कुंजियाँ अनोखी होती हैं। get() गायब कुंजी के लिए वैकल्पिक मान दे सकता है।

अभ्यास: student के points 75 करें और प्रिंट करें।

Hinglish mein samjhein

Dictionary key-value pairs rakhti hai, jaise contact book. Har key unique hoti hai. get() se missing key ka default de sakte ho.

Practice: student points 75 karo aur points print karo.

A small Python example

student = {"name": "Asha", "points": 50}
print(student["name"])
print(student.get("city", "Unknown"))

The browser playground runs real Python with Pyodide. Use sample variables instead of interactive input(). Browser package support differs from desktop Python.

Try this example in the Python playground →

Practise this idea

Update student points to 75 and print the points.

Check answer & explanation
student = {"name": "Asha", "points": 50}
print(student["name"])
print(student.get("city", "Unknown"))
student["points"]=75
print(student["points"])

Assigning student["points"] changes the value associated with that dictionary key. Printing it confirms the new value.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

What does a dictionary store?

  1. Key-value pairs
  2. Only numbers
  3. Only sorted text
Check the quiz answer

Key-value pairs

Keys identify their corresponding values.

References & corrections

Use the official Python documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.