在Python中,由于函数是一种值,我该如何确定变量是否为函数呢?
例如:
boda = len # boda is the length function now
if ?is_var_function(boda)?:
print "Boda is a function!"
else:
print "Boda is not a function!"
这里假设的?is_var_function(x)?
应该在x
是可调用函数时返回true,在x
不是可调用函数时返回false。