The syntax of hasattr() method is:
The hasattr() is called by getattr() to check to see if AttributeError is to be raised or not.
The hasattr() method takes two parameters:
The hasattr() method returns:
class Person: age = 23 name = 'Adam' person = Person() print('Person has age?:', hasattr(person, 'age')) print('Person has salary?:', hasattr(person, 'salary'))
When you run the program, the output will be:
Person has age?: True Person has salary?: False