1# To get all the keys of a dictionary use 'keys()'
2newdict = {1:0, 2:0, 3:0}
3newdict.keys()
4# Output:
5# dict_keys([1, 2, 3])
1my_dict = {'a': 1, 'b': 2, 'c': 3}
2# keys = list(item.keys())
3# the upper commented code give the list of the keys.
4keys = ['a', 'b', 'c', 'd'] # if some body give the list of the keys that wasn't match with my_dict
5
6for key in keys:
7 print(my_dict.get(key, 'default value when key not exist'))
8
9"""output:
101
112
123
13default value when key not exist
14"""
1#!/usr/bin/python
2
3dict = {'Name': 'Zabra', 'Age': 7}
4print "Value : %s" % dict.get('Age')
5print "Value : %s" % dict.get('Education', "Never")