hasattr(object, name) Returns Boolean ( True or False ) after checking attribute of the input object
Read more on Class Object and Attributes →
| Object for which the attribute is to be checked . |
| name of the the attribute . |
Output of hasattr() is True or False.
In above code we got True for the attribute age , but got False for attribute height as it is not declared.
#instantiate the Animal class
print(hasattr(tiger,'age')) # True
print(hasattr(tiger,'height')) # False
«All Built in Functions in Python setattr() delattr() getattr()
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.