The value can be accessed by unique key in the dictionary.
Example - 1:
mydict ={'name':'python','build_year':1991,'Father of Python':"Guido Van Rossum",'Frame_works':['Django','Flask','Web2PY','Torando','kivi'],'versions':[1.0,2.0,3.0],'latest_version':3.6}print(mydict)print("Name : ",mydict['name'])#returns the value of the key 'name'print("Frame Works : ",mydict['Frame_works'])
KeyError: 'C' The get() method is used to avoid such situations. This method returns the value for the given key, if present in the dictionary. If not, then it will return None (if get() is used with only one argument).
The get() method is used to avoid such situations. This method returns the value for the given key, if present in the dictionary. If not, then it will return None (if get() is used with only one argument).
k = mydict.get('versions')
print(k)
print(mydict.items()) #returns key value pair
print(mydict.keys()) #return keys
print(mydict.values()) #return values
mydict['scope'] = 'World Wide' #add key 'scope'
mydict['name'] = "Python Programming Language" #change value of key 'name' as key of this name already exist if it does not
#then it will create key 'name'
print(mydict)