现在的位置: 首页 > 综合 > 正文

python 判定变量是函数

2012年09月14日 ⁄ 综合 ⁄ 共 128字 ⁄ 字号 评论关闭

方法1:


callable(fn) //返回True或False

方法2:


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

方法3:需要引入types模块


import types
isinstance(f, types.FunctionType)

抱歉!评论已关闭.