How to check if an object has a specific attribute in Python

1 Answer

0 votes
class Worker:
    name = "Fox"
    age = 52
    profession = "Programmer"

x = getattr(Worker, 'profession')

if hasattr(Worker, 'profession'):
    print("yes")
else:
    print("yes")


'''
run:

yes

'''

 



answered Dec 12, 2018 by avibootz

Related questions

...