डिक्शनरी को Pythonic तरीके से इस्तेमाल करना

Python में डेटा टाइप्स

Jason Myers

Instructor

डिक्शनरी के साथ और भी Pythonic तरीके

  • .items() ऐसा ऑब्जेक्ट लौटाता है जिस पर आप iterate कर सकते हैं
for gallery, phone_num in art_galleries.items():
    print(gallery)
    print(phone_num)
'Miakey Art Gallery'
'(718) 686-0788'
'Morning Star Gallery Ltd'
'(212) 334-9330'}
'New York Art Expo Inc'
'(212) 363-8280'
Python में डेटा टाइप्स

डिक्शनरी में डेटा जाँचना

  • .get() किसी key के लिए बहुत कुछ जाँचता है
  • in ऑपरेटर ज़्यादा कुशल और साफ है
'11234' in art_galleries
False
if '10010' in art_galleries:
    print('I found: %s' % art_galleries['10010'])
else:
    print('No galleries found.')
I found: {'Nyabinghi Africian Gift Shop': '(212) 566-3336'}
Python में डेटा टाइप्स

अभ्यास करते हैं!

Python में डेटा टाइप्स

Preparing Video For Download...