Python Dictionary | How to access data and can store data

Python Dictionary | How to access data and can store data

How to access data from dictionary

Note - There is no indexing because of unordered 
collections of data print(user1['name'])     
# you cannot do like this

which types of data a dictionary can store ?

 Anything eg - numbers , strings , list ,dictionary

user_info = {
'name' : 'pramod',
'age' : 22 ,
'rollno' :'17691a05b9',
'class' : 'B-Tech'}

 print(user_info['name'])
 print(user_info['age'])
 print(user_info['rollno'])
 print(user_info['class'])

How to add data to empty dictionary

user_info2 = {}
user_info2['name'] = 'prem kumar'user_info2['age'] = 22
 print(user_info2)

Python Dictionary | How to access data and can store data

Leave a Comment

Your email address will not be published. Required fields are marked *