Skip to main content

Command Palette

Search for a command to run...

Easy Python Dictionary Practice for Beginners

Updated
2 min readView as Markdown
Easy Python Dictionary Practice for Beginners
A
I co-founded🫆digizen (fighting internet chaos 🧠), building an AI app to tackle misinformation, and running ideaGeek to turn “I have an idea” into real startups. I also share tech + travel on YouTube (TechNomad & Rz Omar). I touch grass too 🌱… but mostly to debug life 💻

🔹 Exercise 1: Create a Dictionary

Create a dictionary named student with the following key-value pairs:

  • name: "John"

  • age: 20

  • course: "Computer Science"

Then print the dictionary.


🔹 Exercise 2: Access and Update Values

Using the student dictionary from Exercise 1:

  • Access and print the value for the key "name".

  • Change the value of "age" to 21.


🔹 Exercise 3: Add and Remove Items

Using the same student dictionary:

  • Add a new key "grade" with value "A".

  • Remove the key "course" from the dictionary.


🔹 Exercise 4: Loop Through Dictionary

Write a program to print all keys and values in the student dictionary using a for loop.


🔹 Exercise 5: Nested Dictionary

Create a dictionary called classroom with 2 students, each having a nested dictionary:

{
  "student1": {"name": "Alice", "age": 22},
  "student2": {"name": "Bob", "age": 23}
}

Print the name of student2.


✅ Answers

✅ Exercise 1:

student = {
    "name": "John",
    "age": 20,
    "course": "Computer Science"
}
print(student)

✅ Exercise 2:

print(student["name"])      # Output: John
student["age"] = 21

✅ Exercise 3:

student["grade"] = "A"
del student["course"]

✅ Exercise 4:

for key, value in student.items():
    print(key, ":", value)

✅ Exercise 5:

classroom = {
    "student1": {"name": "Alice", "age": 22},
    "student2": {"name": "Bob", "age": 23}
}
print(classroom["student2"]["name"])   # Output: Bob

Python

Part 7 of 10

I break down Python basics with clear explanations and practical exercises. Whether you're a beginner or looking to refresh your skills, follow along to strengthen your Python fundamentals through hands-on practice. Let's code and grow together!

Up next

Python Practice Exercises for New Learners

🔹 Exercise 1: Working with Lists Write a program that: Creates a list of 5 numbers Adds a new number to the list Removes the second number Prints the list 🔹 Exercise 2: Conditions with Loops Create a list of numbers from 1 to 10. Use a for l...

More from this blog

T

TechNomad

46 posts

TechNomad is mostly coding exercises, not long boring explanations 😌. I share what I teach and learn through hands-on problems—mainly for my students, but anyone can jump in. If you learn by doing (and breaking things), you’ll fit right in. Less theory, more “try this and see what happens.”