The hasattr()
function checks whether an object has an attribute with the given name. An attribute can be a variable, method, property, data member, etc.
hasattr(obj, attr)
obj |
The object of which the attribute has to be checked |
attr |
A string specifying the name of the the attribute whose presence has to be tested in obj . |
The function returns True
if the object contains the specified attribute name, otherwise False.