CHAPTER 10
Dictionary
Key-value pairs में data store करना — Python का powerful data structure
Advertisement
Dictionary Basics
Dictionary एक real शब्दकोश की तरह है। हर key के साथ एक value होती है।
python
student = {
"naam": "प्रिया",
"umar": 20,
"marks": 85,
"city": "दिल्ली"
}
print(student["naam"]) # प्रिया
print(student.get("phone", "N/A")) # N/A
student["marks"] = 90 # update
student["email"] = "p@g.com" # add
del student["city"] # delete
print(student.keys())
print(len(student))
OUTPUT
प्रिया
N/AAdvertisement
Dictionary Loop
Dictionary के keys, values और items पर loop करना।
python
marks = {"Math": 85, "Science": 92, "Hindi": 78}
# Items loop करना
for subject, score in marks.items():
print(f"{subject}: {score}")
# Nested Dictionary
school = {
"s1": {"naam": "राम", "marks": 85},
"s2": {"naam": "सीता", "marks": 92}
}
print(school["s2"]["naam"]) # सीता
OUTPUT
Math: 85
Science: 92
Hindi: 78
सीता🎯 QUICK QUIZ — Chapter 10
Dictionary क्या है?
Advertisement