Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!
This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join 11 million other learners and get started learning Python for data science today!
Good news! You can save 25% off your Datacamp annual subscription with the code LEARNPYTHON23ALE25 - Click here to redeem your discount
शब्दकोश
A dictionary एक डेटा प्रकार है जो arrays के समान होता है, लेकिन indexes के बजाय keys और values के साथ काम करता है। एक dictionary में संग्रहीत प्रत्येक value को एक key का उपयोग करके एक्सेस किया जा सकता है, जो किसी भी प्रकार की object (एक string, एक number, एक list, आदि) हो सकती है, इसके index का उपयोग करके इसे संबोधित करने के बजाय।
उदाहरण के लिए, फोन नंबरों का एक डेटाबेस dictionary का उपयोग करके इस तरह संग्रहीत किया जा सकता है:
वैकल्पिक रूप से, एक dictionary को निम्नलिखित नोटेशन में समान values के साथ इनिशियलाइज़ किया जा सकता है:
Iterating over dictionaries
Dictionaries को list की तरह iterate किया जा सकता है। हालांकि, एक list के विपरीत, dictionary उसमें संग्रहीत values के क्रम को नहीं रखता है। key value pairs पर iterate करने के लिए, निम्नलिखित सिंटैक्स का उपयोग करें:
Removing a value
किसी निर्दिष्ट index को हटाने के लिए, निम्नलिखित नोटेशन्स में से किसी एक का उपयोग करें:
या:
Exercise
फोनबुक में "Jake" को 938273443 फोन नंबर के साथ जोड़ें, और फोनबुक से Jill को हटाएं।
This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!
