Python में Dictionary डेटा मानों का एक unordered collection है, जो मानचित्र जैसे डेटा मानों को संग्रहीत करने के लिए उपयोग किया जाता है, जो अन्य डेटा प्रकारों के विपरीत होता है जो तत्व के रूप में केवल एक मान रखते हैं, dictionary कुंजी रखता है: मूल्य जोड़ी।
इसे अधिक अनुकूलित करने के लिए dictionary में कुंजी मान प्रदान किया जाता है। एक dictionary में प्रत्येक कुंजी-मूल्य जोड़ी को कोलन द्वारा अलग किया जाता है: जबकि प्रत्येक कुंजी को 'अल्पविराम' से अलग किया जाता है।
Python में एक dictionary वास्तविक दुनिया में dictionary के समान काम करता है। एक dictionary की कुंजी अद्वितीय और अपरिवर्तनीय डेटा प्रकार जैसे स्ट्रिंग्स, इंटेगर्स और टुपल्स होना चाहिए, लेकिन कुंजी-मानों को दोहराया जा सकता है और किसी भी प्रकार का होना चाहिए।
एक dictionary में keys polymorphism की अनुमति नहीं देता है।
Python में, एक dictionary को 'कॉमा' से अलग curly {} ब्रेसिज़ के भीतर तत्वों के अनुक्रम को रखकर बनाया जा सकता है। dictionary में मूल्यों की एक जोड़ी होती है, एक कुंजी होती है और अन्य संबंधित जोड़ी तत्व इसकी कुंजी: मान होता है।
किसी dictionary में मान किसी भी डेटा टाइप का हो सकता है और इसे डुप्लिकेट किया जा सकता है, जबकि कुंजियों को दोहराया नहीं जा सकता है और immutable होना चाहिए।
Dictionary built-in फ़ंक्शन dict () द्वारा भी बनाया जा सकता है। एक खाली dictionary केवल curly ब्रेसिज़ {} से रखकर बनाया जा सकता है।
# Creating an empty Dictionary Dict = {} print("Empty Dictionary: ") print(Dict) # Creating a Dictionary # with Integer Keys Dict = {1: 'Htmlt', 2: 'For', 3: 'Htmlt'} print("\nDictionary with the use of Integer Keys: ") print(Dict) # Creating a Dictionary # with Mixed keys Dict = {'Name': 'Htmlt', 1: [1, 2, 3, 4]} print("\nDictionary with the use of Mixed Keys: ") print(Dict) # Creating a Dictionary # with dict() method Dict = dict({1: 'Htmlt', 2: 'For', 3:'Htmlt'}) print("\nDictionary with the use of dict(): ") print(Dict) # Creating a Dictionary # with each item as a Pair Dict = dict([(1, 'Htmlt'), (2, 'For')]) print("\nDictionary with each item as a pair: ") print(Dict)