.
# 创建对象a
>>> a = A()
# 检测是否存在属性 name
>>> hasattr(a,"name")
True
>>> hasattr(a,"age")
False
# 检测是否存在函数...fun1
>>> hasattr(a,"fun1")
True
>>> hasattr(a,"fun2")
False
#判断fun1是否为一个函数,如果是一个函数,返回True
>>> callable...(getattr(a,"fun1"))
True
#判断fun1是否为一个函数,如果不是一个函数,返回False
>>> callable(getattr(a,"name"))
False
#判断fun2...是否为一个函数,如果没有定义,则抛出异常
>>> callable(getattr(a,"fun2"))
Traceback (most recent call last):
File "", line 1, in
AttributeError: A instance has no attribute 'fun2'
#直接调用fun1函数
>>> getattr(a,