Python Dictionary data type example
- #creating dictionary
- dict = {'Name' : 'hooper','Sal' : 122,'id':222,'Address':'hyd'};
- print dict
- #accessing dict elements
- print "first element is dict['Name']:", dict['Name'];
- #updating dict elements
- print "ofter updation dice elements are"
- dict['Name']='satya';
- dict['comany']='heeperlabs';
- print dict
- # iteration dictionary elements
- for items in dict.items():
- print items
- # deleting single element from dictionary
- del dict['Sal'];
- print dict
- # deleting all element from dictionary
- dict.clear();
- print dict
- # deleting entire dictionary
- del dict
- print dict
No comments:
Post a Comment