Important Notice:

Course Content
Dictionary in Python (Chapter-9) M3-R5
About Lesson

Accessing Value from Dictionary

                List और Tuple में value को access करने के लिए उनकी ‘index’ का इस्तेमाल किया जाता है। वैसे ही dictionary की values को access करना हो तो उनकी square brackets([]) में ‘keys’ का इस्तेमाल किया जाता है

d={10:’Atul’,11:’Vimal’,12:’vishal’,13:’Vikash’}

print(d[10])                           # Atul

print(d[11])                           # Vimal

print(d[12])                           # vishal

print(d[13])                           # Vikash

Note:-  dictionary  से element को access करने के लिए get keyword का प्रयोग कर सकते हैं।

       a={50:’Aman’, 51:’Raman’, 52:’Suman’}

print(a)                                                   # {50: ‘Aman’, 51: ‘Raman’, 52: ‘Suman’}

print(a.get(51))                                     #Raman

Note:- यदि specify किया गया key available नही है तो, ‘keyError’ message आता है।

 

Accessing Value from Dictionary

              To access the value in List and Tuple, their ‘index’ is used. Similarly, if we want to access the values of the dictionary, then ‘keys’ are used in their square brackets ([]).

d={10:’Atul’,11:’Vimal’,12:’vishal’,13:’Vikash’}

print(d[10])                           # Atul

print(d[11])                           # Vimal

print(d[12])                           # vishal

print(d[13])                           # Vikash

Note:-  To access the element from dictionary, you can use get keyword.

       a={50:’Aman’, 51:’Raman’, 52:’Suman’}

print(a)                                                   # {50: ‘Aman’, 51: ‘Raman’, 52: ‘Suman’}

print(a.get(51))                                     #Raman

Note:- If the specified key is not available, ‘keyError’ message appears.

error: Content is protected !!