python 判定变量是函数

方法1:


callable(fn) //返回True或False

方法2:


hasattr(fn, '__call__') //返回True或False

方法3:需要引入types模块


import types
isinstance(f, types.FunctionType)

原文地址:https://www.cnblogs.com/rubylouvre/p/2095108.html