Important Notice:

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

Creating Dictionary

Syntax:-                       d={key1:value1,key2:value2,………}

Empty dictionary:-

d={}

print(d)                                           # {}

print(type(d))                                  # <class ‘dict’>

Adding element in empty dictionary:-

d={}

d[10]=’akhilesh’

d[11]=’monu’

d[12]=’sonu’

d[13]=’ankit’

print(d)                                    # {10: ‘akhilesh’, 11: ‘monu’, 12: ‘sonu’, 13: ‘ankit’}

Note:- dictionary में directly value भी assign किया जा सकता है।

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

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

print(type(a))                                        #<class ‘dict’>         

 

 

Creating Dictionary

Syntax:-                       d={key1:value1,key2:value2,………}

Empty dictionary:-

d={}

print(d)                                           # {}

print(type(d))                                  # <class ‘dict’>

Adding element in empty dictionary:-

d={}

d[10]=’akhilesh’

d[11]=’monu’

d[12]=’sonu’

d[13]=’ankit’

print(d)                                           # {10: ‘akhilesh’, 11: ‘monu’, 12: ‘sonu’, 13: ‘ankit’}

 

Note:- Value can also be assigned directly to the dictionary.

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

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

print(type(a))                                        #<class ‘dict’>                                                                    

error: Content is protected !!