Python dictionary built-in method get application, if we need to obtain the dictionary value, we have two methods, one is through dict [& amp; & amp; 39; key & amp; 39;]. The other method is the dictget () method. Python dictionary built-in method get application. if we need to obtain the dictionary value, we have two methods: dict ['key'] and dict. get () method.
Today we will share with you the get () method of the dictionary.
Here we can use a dictionary to make a small game. assume that the user enters the string "1", "2", or "3" on the terminal and returns the corresponding content, "error" is returned"
Some friends may use the if elif else judgment statement to perform operations, which is indeed acceptable, but tedious. It is very convenient to recommend a dictionary get () method.
Info = {'1': 'First ', '2': 'second', '3': 'third '}
Number = raw_input ('input type you number :')
Print info. get (number, 'error ')
In this way, a line of code get may be able to complete several lines of code in the python judgment statement.