Returns True if the object has the named attribute.
Syntax
hasattr(object, name)Example
Enter values below to update the example in real time.
class→Dog→def→__init__→self→name→dog→print→hasattr→class Dog:
def __init__(self):
self.name = "Rex"
dog = Dog()
print(hasattr(dog, "name")) # True
print(hasattr(dog, "age")) # False