Apr-19-2024, 06:21 AM
hi
in the below code:
in help(dict.get), what are the meanings of self and / ?
in line 14, I want to use dict.get as in help(dict.get), but I am taken with an error(error message is commented in the above code) What is the problem?
in line 15, I omitted the default= from line 14, and I don't have the error message.
thanks for any guidance
in the below code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#dict_get.py print ( help ( dict .get)) ''' Help on method_descriptor: get(self, key, default=None, /) Return the value for key if key is in the dictionary, else default. ''' dict_1 = { 'ali' : 12 , "mohammad" : 15 , "fatemeh" : 20 } dict_1.get( 'ali' ) #12 dict_1.get( 'fatemeh' ) #20 dict_1.get( 'fatemeh' ,default = '40' ) #line 14 # Traceback (most recent call last): # File "<stdin>", line 1, in <module> # TypeError: dict.get() takes no keyword arguments dict_1.get( 'fatemeh' , '40' ) 20 dict_1.get( 'fatemeh440' , '40' ) '40' |
in line 14, I want to use dict.get as in help(dict.get), but I am taken with an error(error message is commented in the above code) What is the problem?
in line 15, I omitted the default= from line 14, and I don't have the error message.
thanks for any guidance