Friday, July 3, 2015

Python Dictionary data type example


  1. #creating dictionary

  2. dict = {'Name' : 'hooper','Sal' : 122,'id':222,'Address':'hyd'};
  3. print dict

  4. #accessing dict elements
  5. print "first element is dict['Name']:", dict['Name'];

  6. #updating dict elements
  7. print "ofter updation dice elements are"

  8. dict['Name']='satya';
  9. dict['comany']='heeperlabs';
  10. print dict

  11. # iteration dictionary elements

  12. for items in dict.items():
  13.  print items

  14. # deleting single element from dictionary
  15. del dict['Sal'];
  16. print dict

  17. # deleting all element from dictionary

  18. dict.clear();
  19. print dict

  20. # deleting entire dictionary

  21. del dict
  22. print dict

No comments:

Post a Comment