Manual
The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)
直译
参数是一个对象和一个字符串,如果字符串是对象属性之一的命名,则返回True,否则False。这通过调用getattr(object, name)方法来实现,并观察它是否引发AttributeError。
实例
>>> class CSDN:
def foobar(self):
print('Hello CSDNer!')
>>> hasattr(CSDN, 'foobar')
True