Python Dictionaries: Key-Value Pairs and Access

🚀 Day 10/60 – Dictionaries in Python (Key-Value Magic 🔑) Lists store values… But what if you need labels with values? That’s where dictionaries shine 👇 🧠 What is a Dictionary? A dictionary stores data in key-value pairs. person = { "name": "Adeel", "age": 25, "city": "Lahore" } 🔍 Access Values print(person["name"]) # Adeel print(person["age"]) # 25 ➕ Add / Update Values person["job"] = "Data Engineer" # Add person["age"] = 26 # Update ❌ Remove Item person.pop("city") 🔁 Loop Through Dictionary for key, value in person.items(): print(key, value) ⚡ Real Example student = { "name": "Ali", "marks": 90 } if student["marks"] > 80: print("Top Student") ❌ Common Mistake print(person.name) # ❌ Error Correct: print(person["name"]) # ✅ 🔥 Pro Tip Keys must be unique & immutable (like strings, numbers, tuples) 🔥 Challenge for today Create a dictionary: 👉 Store your name, age, and favorite language 👉 Print each key and value Comment “DONE” when finished ✅ Follow Adeel Sajjad to stay consistent for 60 days 🚀 #Python #LearnPython #PythonProgramming #Coding #Programming

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories