Python में डेटा टाइप्स
Jason Myers
Instructor
dict() या {} से बनाएँart_galleries = {}
for name, zip_code in galleries:
art_galleries[name] = zip_code
for name in sorted(art_galleries)[-5:]:
print(name)
Zwirner David Gallery
Zwirner & Wirth
Zito Studio Gallery
Zetterquist Galleries
Zarre Andre Gallery
art_galleries['Louvre']
|--------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-1-4f51c265f287> in <module>()
--> 1 art_galleries['Louvre']
KeyError: 'Louvre'
.get() मेथड आपको बिना एरर या exception हैंडलिंग के key को सुरक्षित रूप से एक्सेस करने देता है.get() डिफ़ॉल्ट रूप से None लौटाता है, या आप लौटाने के लिए कोई वैल्यू दे सकते हैंart_galleries.get('Louvre', 'Not Found')
'Not Found'
art_galleries.get('Zarre Andre Gallery')
'10011'
Python में डेटा टाइप्स