2019-02-26
阅读量:
590
python如何启用反射功能
反射启用函数包括type(),isinstance(),callable(),dir()和getattr()。
- type和isinstance
- Callable():可调用意味着可以调用的任何东西。对于对象,确定是否可以调用它。通过提供__call __()方法可以使类可调用。如果传递的对象显示为可调用,则callable()方法返回True。如果不是,则返回False。
Examples:
x = 5
def testFunction():
print("Test")
y = testFunction
if (callable(x)):
print("x is callable")
else:
print("x is not callable")
if (callable(y)):
print("y is callable")
else:
print("y is not callable")
Output:
x is not callable
y is callable






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论