Menu Bar

Horizontal Scrollable Menu

ads

Search This Blog

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 thid

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)

No comments:

ads3