Riju21

5_dictionary

Mar 27th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. info = {'name' : 'riju','id': 1,'email': '[email protected]'}
  2.  
  3. for key,val in info.items():  # to get all keys & values
  4.    print( key,'=>',val )
  5.  
  6. print( info.keys() )          # to get all keys
  7. print( info.values() )        # to get all values
  8. print( info.items() )         # to get all keys & values as list
  9.  
  10. info.update( {'email': '[email protected]', 'id': 2} )  # to update any values
  11. print( info )
  12.  
  13. del info['id']           # to delete any key
  14. print( info )
  15.  
  16. print( info.get( 'age', 'not found' ) )  # get method doesn't show error if key not found
Advertisement
Add Comment
Please, Sign In to add comment