Python Dictionary in Hindi | पाइथन डिक्शनरी क्या है और कैसे उपयोग करें?
📘 Chapter 8: पाइथन में डिक्शनरी (Dictionary in Python in Hindi)
Python में Dictionary एक ऐसा डेटा टाइप है जिसमें key-value pairs में जानकारी store की जाती है। यह unordered होता है और mutable (बदला जा सकता है)।
🔹 Dictionary कैसे बनाएं?
student = {
"name": "Amit",
"age": 20,
"grade": "A"
}
print(student)
🔹 Dictionary में value एक्सेस करना:
print(student["name"])
print(student.get("age"))
🔹 Key जोड़ना या बदलना:
student["city"] = "Delhi"
student["grade"] = "A+"
print(student)
🔹 Key हटाना:
student.pop("age")
del student["grade"]
print(student)
🔹 Loop के साथ dictionary:
for key in student:
print(key, ":", student[key])
🔹 कुछ जरूरी methods:
print(student.keys()) # सभी keys
print(student.values()) # सभी values
print(student.items()) # सभी key-value जोड़े
🔹 Nested Dictionary:
students = {
"s1": {"name": "Rahul", "age": 18},
"s2": {"name": "Anjali", "age": 19}
}
print(students["s1"]["name"])
📌 इस चैप्टर में आपने सीखा:
- Dictionary क्या होती है
- Keys और values कैसे काम करते हैं
- Methods जैसे get(), keys(), items()
- डिक्शनरी में डेटा जोड़ना, बदलना और हटाना
- Nested dictionary का उपयोग
➡️ अगला चैप्टर:
Chapter 9: Python Sets – सेट क्या होता है और इसे कब उपयोग करें?
Post a Comment
0 Comments