Ruby's Louvre

每天学习一点点算法

导航

python 判定变量是函数

方法1:


callable(fn) //返回True或False

方法2:


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

方法3:需要引入types模块


import types
isinstance(f, types.FunctionType)

posted on 2011-06-30 23:21  司徒正美  阅读(2862)  评论(1编辑  收藏  举报