hasattr(object, name)
判断一个对象里面是否有name属性或者name方法,返回BOOL值,有name特性返回True, 否则返回False。需要注意的是name要用引号括起来
""" hasattr(object, name) 判断一个对象里面是否有name属性或者name方法,返回BOOL值,有name特性返回True, 否则返回False。 需要注意的是name要用括号括起来 """ class test(): name = "lihuanyu" def fun(self): print("你好,中国") test_hasattr = test() print(hasattr(test_hasattr,"name")) print(hasattr(test_hasattr,"fun")) print(hasattr(test_hasattr,"China"))