Python 内建函数 - callable(object)
2017-03-13 15:08
513 查看
Manual
直译
实例
数字值
字符串
迭代
函数
类有__call__ 方法
直译
实例
数字值
字符串
迭代
函数
类有__call__ 方法
Manual
Return True if the object argument appears callable, False if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); instances are callable if their class has a __call__() method.直译
如果object参数可调用则返回True,否则False。如果返回真,参数仍有可能调用失败,如果否,调用对象则永远不会成功。注意类是可调用的(调用一个类将返回一个新的实例);如果类有__call__() 方法,则它们的实例可调用。实例
数字(值)
>>> callable(17) False
字符串
>>> callable('CSDN') False
迭代
>>> callable(range(10)) False
函数
>>> def csdn(x): t = x for i in range(10): t += i return t >>> csdn(2) 47 >>> callable(csdn(2)) False
类(有__call__() 方法)
>>> class CSDN: def __call__(self): return 47 def csdn(self, x): t = x for i in range(10): t += i return t >>> c = CSDN() >>> c.csdn(2) 47 >>> callable(c) True >>> callable(CSDN) True
相关文章推荐
- Python包导入(TypeError: 'module' object is not callable),及一定要记住Python成员函数第一个参数值是self。
- python函数 callable(object)
- 【Python】TypeError: 'module' object is not callable 原因分析
- python错误TypeError: 'module' object is not callable 的解决方法
- python 遇到 'unicode' object is not callable 错误
- 【Python】unicode' object is not callable
- Python 内建函数 - repr(object)
- python错误TypeError: 'module' object is not callable 的解决方法
- python import 错误 TypeError: 'module' object is not callable
- 【python系列】TypeError: 'module' object is not callable 原因分析
- python函数日积月累 basestring()、any()、all()、callable()、divmod()
- python的exit退出时,提示TypeError: 'str' object is not callable
- python class中遇到的TypeError: 'module' object is not callable
- Python函数参数传递方式(call by object reference)以及一致性
- TypeError: 'module' object is not callable 原因分析(python模块导入注意事项)
- python错误TypeError: 'module' object is not callable 的解决方法
- python内建函数hasattr(object, name)
- 【Python】TypeError: 'module' object is not callable 原因分析
- Python标准库:内置函数callable(object)
- python callable 函数