Q:

get function in dictionary

dict = {'color': 'blue', 'shape': 'square', 'perimeter':20}
dict.get('shape') #returns square

#You can also set a return value in case key doesn't exist (default is None)
dict.get('volume', 'The key was not found') #returns 'The key was not found'
8
#The get() method in  dictionary returns:
#the value for the specified key if key is in dictionary.
#None if the key is not found and value is not specified.
#value if the key is not found and value is specified.
# value is provided
print('Salary: ', person.get('salary', 0.0))
7

New to Communities?

Join the community