热线电话:13121318867

登录
2019-02-26 阅读量: 590
python如何启用反射功能

反射启用函数包括type(),isinstance(),callable(),dir()和getattr()。

  1. type和isinstance
  2. 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.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子