Important Notice:

Dictionary in Python

Dictionary in Python

7 views 2 min read
Dictionary in Python (डिक्शनरी) :-

Dictionary (डिक्शनरी) Python का एक Built-in Data Type है, जिसका उपयोग Data को Key-Value Pair के रूप में Store करने के लिए किया जाता है।

Dictionary में प्रत्येक Key किसी Value को पहचानने (Identify) के लिए उपयोग की जाती है। प्रत्येक Key सामान्यतः Unique (अद्वितीय) होनी चाहिए, जबकि Values Duplicate (दोहराई हुई) हो सकती हैं।

Dictionary एक Mutable (परिवर्तनीय), Dynamic (गतिशील) तथा Mapping Data Structure है। आधुनिक Python में Dictionary Insertion Order (जोड़ने का क्रम) को भी बनाए रखती है।

Python में Dictionary को Curly Braces ({}) के अंदर लिखा जाता है। प्रत्येक Key और Value के बीच Colon (:) लगाया जाता है तथा प्रत्येक Key-Value Pair को Comma (,) द्वारा अलग किया जाता है।

महत्वपूर्ण: Dictionary का उपयोग ऐसे Data को Store करने के लिए किया जाता है जिसे Key की सहायता से आसानी से Access, Add, Update और Delete किया जा सके।

Syntax -
dictionary_name = {
    key1: value1,
    key2: value2,
    key3: value3
}
 
Example -
 
student = {
    "name": "Rahul",
    "age": 20,
    "course": "O Level"
}

print(student)
 
Output-
{'name': 'Rahul', 'age': 20, 'course': 'O Level'}
 
Key-Value Pair Example -
 
student = {
    "name": "Rahul",
    "age": 20
}

यहाँ:

"name" → Key
"Rahul" → Value
"age" → Key
20 → Value
 
English

A Dictionary is a Built-in Data Type in Python that is used to store data in the form of Key-Value Pairs.

In a Dictionary, each Key is used to identify a particular Value. Each Key should generally be unique, while Values can be duplicated.

A Dictionary is a Mutable, Dynamic, and Mapping Data Structure. In modern versions of Python, a Dictionary also preserves insertion order.

In Python, a Dictionary is written inside Curly Braces ({}). A Colon (:) is used to separate a Key and its Value, and each Key-Value Pair is separated by a Comma (,).

Important: A Dictionary is used to store data that can be easily accessed, added, updated, and deleted using Keys.

Syntax -
 
dictionary_name = {
    key1: value1,
    key2: value2,
    key3: value3
}
 
Example -
student = {
    "name": "Rahul",
    "age": 20,
    "course": "O Level"
}

print(student)
 
Output-
 
{'name': 'Rahul', 'age': 20, 'course': 'O Level'}
 
Key-Value Pair Example -
 
student = {
    "name": "Rahul",
    "age": 20
}

Here:

"name" → Key
"Rahul" → Value
"age" → Key
20 → Value

Related Notes