python - Why does this function return None, but when I type out what it does manually, it returns something different? -
here code:
dict = { "a":"1" } def dict_find(x): print dict.get('x') dict_find('a') print dict.get('a') the output dict_find('a') none, output manually writing out print dict.get('a') 1.
that because function not use variable x string 'x', not key of dict.
additionally, function has no return statement. function without return statement return none.
also, should not use dict variable name, since built-in type.
dic = {"a":"1"} def dict_find(x): return dic.get(x)
Comments
Post a Comment