Python Tutorial in Hindi #9 - Dictionaries
Python Dictionaries Tutorial for Beginners | Create, Update & Use Dictionaries | Mohit Decodes
Learn Python Dictionaries — one of the most powerful data structures!
In this beginner-friendly tutorial by Mohit Decodes, you'll understand how to create and use Dictionaries in Python — a must-have skill for modern Python programming.
✅ Topics Covered:
Creating Dictionaries
Accessing Dictionary Items
Updating Values
Deleting Items
Useful Dictionary Methods
Working with Nested Dictionaries
Practical Examples & Tips
# ✅ Create a Dictionary
student = {
"name": "Mohit",
"age": 25,
"course": "Python",
"marks": [88, 92, 79],
"isEnrolled": True
}
# ✅ Print the Dictionary
print(student)
# ✅ Access Dictionary Values
print(student["name"]) # Access using key
print(student.get("course")) # Using get() method
# ✅ Update Values
student["age"] = 26
student["city"] = "Delhi" # Add new key-value pair
print(student)
# ✅ Delete Items
del student["isEnrolled"] # Delete a specific key
print(student)
# ✅ pop() - remove and return value
removed_value = student.pop("course")
print("Removed:", removed_value)
print(student)
# ✅ popitem() - remove last inserted item
student.popitem()
print(student)
# ✅ Dictionary Methods
print(student.keys()) # All keys
print(student.values()) # All values
print(student.items()) # All key-value pairs
# ✅ Loop through Dictionary
for key, value in student.items():
print(f"{key} : {value}")
# ✅ Copy Dictionary
student2 = student.copy()
student2["name"] = "Rohit"
print("Copy:", student2)
# ✅ Nested Dictionary Example
students = {
"student1": {"name": "Mohit", "age": 25},
"student2": {"name": "Rohit", "age": 22},
}
print(students["student1"]["name"]) # Access nested value