Friday , September 20 2024

What will be the output of the following code? class A: A = 1 print(hasattr(A,’A’))

Questions BankCategory: Python Essentials 2What will be the output of the following code? class A: A = 1 print(hasattr(A,’A’))
What will be the output of the following code?

class A:
    A = 1
 
 
print(hasattr(A,'A'))
  • False
  • 1
  • True
  • 0

Explanation: The hasattr() function returns True if a specified object has some specified attribute. The function takes two arguments: the name of the object whose attribute is to be tested, and the name of the attribute.

The code returns True because class A has the attribute A.

More Questions: Python Essentials 2 – Module 3 Test