according to the doc, the get method of a dict can have two argument: key and a value to return if that key is not in the dict. However, when the second argument is a function, it'll run regardless of whether the key is in the dict or not:
def foo():
print('foo')
params={'a':1}
print(params.get('a', foo()))
# foo
# 1
As shown above, the key a
is in the dict, but foo()
still runs. What happens here?