Important Notice:

Dictionary

Dictionary

35 views 2 min read

Dictionary  (डिक्शनरी) :-

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

Dictionary में प्रत्येक Key (कुंजी) के साथ एक Value (मान) जुड़ी होती है। किसी Value को प्राप्त करने के लिए उसकी संबंधित Key का उपयोग किया जाता है।

Dictionary एक Mutable (परिवर्तनीय), Dynamic (गतिशील) तथा Insertion Ordered (Python 3.7+ में) Data Structure है।

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

Important: - Dictionary में प्रत्येक Key Unique (अद्वितीय) होनी चाहिए। यदि एक ही Key को एक से अधिक बार लिखा जाता है, तो अंतिम (Last) Value ही सुरक्षित रहती है और पहले वाली Value Replace (प्रतिस्थापित) हो जाती है।

महत्वपूर्ण: Dictionary में Data को Index Number से नहीं बल्कि Key के माध्यम से Access किया जाता है।

English

A Dictionary is a built-in data type in Python used to store data in the form of Key-Value Pairs.

In a Dictionary, each Key is associated with a Value. A value can be accessed using its corresponding key.

A Dictionary is a Mutable, Dynamic, and Insertion Ordered (in Python 3.7 and later) data structure.

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

Important: - Each Key in a Dictionary must be Unique. If the same key is specified more than once, the last value is retained, and the previous value is replaced.

Important: -Data in a Dictionary is accessed using its Key, not by an Index Number.

 

Syntax :-

dictionary_name = {
    key1: value1,
    key2: value2,
    key3: value3
}
 
Example-
student = {
    "name": "Aman",
    "age": 18,
    "marks": 85
}

print(student)
 
Output-
{'name': 'Aman', 'age': 18, 'marks': 85}
 
Example-
student = {
    "name": "Rahul",
    "age": 15,
    "city": "Delhi",
    "age": 16
}

print(student)
 
Output-
{'name': 'Rahul', 'age': 16, 'city': 'Delhi'}
 
 

Related Notes