Home >> Python Tutorial >> Python Dictionary
Edit Template
Edit Template

Python dictionary in Hindi

What is Python Dictionary in Hindi

python में dictionary एक unordered collection होता है जो { } के अंदर key pair values को store करता है, key pair values को comma से separated किया जाता है ,और हर value को comma separate करते हैं.

🐍
dictionary.py
Copy to clipboard
# Using curly braces
dict1 = {"name": "Lisa", "age": 24, "study": "Pyrhon"}
print(dict1)
# Output:
# {'name': 'Lisa', 'age': 24, 'study': 'Python'}

# Using dict() method
dict2 = dict(name="Lisa", age=24, study="Python")
print(dict2)
# Output:
# {'name': 'Lisa', 'age': 24, 'study': 'Python'}

How to Access Dictionary items in Hindi

dictionary में values को access करने के लिए उसकी key का use किया जाता है

🐍
access.py
Copy to clipboard
dict1 = {"name": "Retesh", "age": 25, "city": "Delhi"}
print(dict1["name"]) # Outpot: Retesh

How to Change Dictionary items in Hindi

dictionary में existing value को change करने के लिए key का use करते हैं

🐍
change.py
Copy to clipboard
dict1 = {"name": "Retesh", "age": 25, "city": "Delhi"}
print(dict1["name"]) # Outpot: Retesh
dict1["name"] = "Daya"
print(dict1["name"]) # Output: Daya

How to Add items in Dictionary in Hindi

dictionary में हम new key pair values को आसानी से add कर सकते हैं

🐍
addd item.py
Copy to clipboard
dict1 = {"name": "Retesh", "age": 25}
dict1["study"] = "Python"
print(dict1)
# Outpot: {'name': 'Retesh', 'age': 25, 'study': 'Python'}

Iterate Dictionary items in Hindi

Dictionary के items को iterate करने के लिए loop का use किया जाता है हम loop का use करके key को iterate कर सकते हैं, value को iterate कर सकते हैं, उन items को भी iterate कर सकते है

🐍
iterate.py
Copy to clipboard
dict1 = {"name": "Retesh", "age": 25, "study": "Python"}

# iterate keys
for i in dict1:
    print(i)

# iterate values
for i in dict1.values():
    print(i)

# iterate items
for i in dict1.items():
    print(i)

What is Nested Dictionary in Hindi

जब हम dictionary के अंदर भी dictionary बनाते हैं तो इस nested dictionary बोलते हैं.

🐍
nested dictionary.py
Copy to clipboard
nest_dict = {
    "student1": {"name": "Roli", "age": 20},
    "student2": {"name": "Roshan", "age": 25}
}
print(nest_dict)
# Output:
# {'student1': {'name': 'Roli', 'age': 20},
#    'student2': {'name': 'Roshan', 'age': 25}}

Dictionary Methods in Hindi

python मे dictionary के लिए build-in methods होते है, जिनका use करके dictionary के साथ अलग अलग operation perform किया जाता है। 

Syntex:

method को किसी भी variable के साथ use करने के लिए dot ( . ) का use करते है।

Example:

fromkey() : इस method का use हम new dictionary को create करने के लिए करते है जिसमे हम new keys लेते है और उसमे same value को assign करते है। 

🐍
fromkey.py
Copy to clipboard
keys = ("Name", "Age", "Study")
values = "NA"
student = dict.fromkeys(keys,values)
print(student)
# Output: {'Name': 'NA', 'Age': 'NA', 'Study': 'NA'}

How to Remove Dictionary items in Hindi

pop(): Specified key के pair को remove करता है और value return करता है। 

popitem(): Last inserted key-value pair को remove करता है।

del: Specified key के pair को delete करता है।

clear(): सारे items को remove करता है। 

🐍
remove.py
Copy to clipboard
dict1 = {"name": "Retesh", "age": 25, "study": "Python"}

# Using pop()
dict1.pop("study")
print(dict1)
# Outpot: {'name': 'Retesh', 'age': 25}

# Using popitems()
dict1.popitem()
print(dict1)
# Output : {'name': 'Retesh}

# Using del
del dict1["name"]
print(dict1) # Output: {}

#using clear()
dict1 = {"name": "Retesh", "age": 25, "study": "Python"}
dict1.clear()
print(dict1)  # Output: {}

How to Copy Dictionaries in Hindi

copy(): Shallow copy बनाता है।

dict(): Shallow copy बनाता है।

🐍
copy.py
Copy to clipboard
dict1 = {"name": "Retesh", "age": 25, "study": "Python"}

# Using copy()
dict2 = dict1.copy()
print(dict2)
# Output:
# {'name': 'Retesh', 'age': 25, 'study': 'Python'}

# Using dict()
dict3 = dict(dict1)
print(dict3)
# Output:
# {'name': 'Retesh', 'age': 25, 'study': 'Python'} 

Dictionary के कुछ और useful methods :

 

get(): Specified key की value return करता है।

items(): Dictionary के items (key-value pairs) return करता है।

keys(): Dictionary के keys return करता है।

setdefault(): Specified key की value return करता है, अगर key exist नहीं करती, तो उस key और default value को add करता है।

update(): Specified key-value pairs से dictionary को update करता है।

values(): Dictionary के values return करता है।

उम्मीद करते है कि आपको Python Dictionary अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे,

Add a comment...

  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Fundamentals
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
File Pointer

Table of Contents All Chapters 1. File Pointer 2. File Pointer Methods      2.1. tell() Method      2.2....

File Handling

Table of Contents All Chapters 1. File Handling 2. Types of File 3. open() and close() Methods 4. File Modes...

Python Modules

Table of Contents All Chapters 1. Modules in Python 2. Pre-defined Modules      2.1. math      2.2. random...

Python Iterators

Table of Contents All Chapters 1. Iterators      1.1. Iterable      1.2. Iterator      1.3. Iterator Protocol...

Python Polymorphism

Table of Contents All Chapters 1. Polymorphism 2. Key Concepts of Polymorphism 3. Types of Polymorphism      3.1. Polymorphism...

Python Inheritance

Table of Contents All Chapters 1. Inheritance 2. Concepts of Inheritance 3. Types of Inheritance      3.1. Single Inheritance...

Python Function

Table of Contents All Chapters 1. Python Function 2. Define Function 3. Function Arguments 4. Function Parameters 5. Local and...

Python Dictionary

Table of Contents All Chapters 1. Python Dictionary 2. Access Dictionary items 3. Change Dictionary items 4. Add items in...

Edit Template
Scroll to Top