Search⌘ K
AI Features

Solution: Teach Your Code to Remember Lots of Things!

Explore how to use dictionaries in Python to store and manage information efficiently. Learn how key-value pairs work and how to loop through them to display stored data clearly, building reusable and powerful code structures.

We'll cover the following...

This program stores information about you in a dictionary and then prints each piece of information neatly.

  • The me dictionary holds data in key–value pairs.

    • A key is like a label (e.g., "name").

    • A value is the information that label points to (e.g., "Your Name").

  • me.items() returns all key–value pairs from the dictionary.

  • The for loop goes through each pair one by one, storing them in key and value.

  • The print() statement displays them in a readable format.

Python
me = {
"name": "Your Name",
"hobby": "Something fun",
"language": "Python"
}
for key, value in me.items():
print(key, ": ", value) # Or use key.title() to make it look nicer