Situatie
The hasattr() method returns true if an object has the given named attribute and false if it does not.
Solutie
Pasi de urmat
class Person:
age = 23
name = ‘Adam’
person = Person()
print(‘Person has age?:’, hasattr(person, ‘age’))
print(‘Person has salary?:’, hasattr(person, ‘salary’))
Output:
Person has age?: True
Person has salary?: False
Leave A Comment?