Home >>Python Built-in Functions >Python hasattr() Function
Python hasattr() function is used to return True value if the required object has the specified attribute otherwise it will return False.
Syntax:hasattr(object, attribute)
Parameter | Description |
---|---|
object | This is a required parameter. It defines the given object. |
attribute | This parameter defines the name of the attribute you want to check if exists. |
class Person:
name = "Jerry"
age = 21
country = "India"
x = hasattr(Person, 'age')
print(x)
class Person:
name = "Jerry"
age = 21
country = "India"
x = hasattr(Person, 'job')
print(x)