Simple Ways to Check if an Object has Attribute in Python ...
www.pythonpool.com › python-check-if-object-hasJun 23, 2021 · Attribute does not exist Python Check If Object Has Attribute using if else block. We can also use an if-else block for checking if the attribute exists or not. If the attribute exists, the hasattr() function shall return True, and the if block shall be executed, thereby printing the value of that attribute. But, if the attribute does not exist, then hasattr() shall return False, and the else part will be executed.