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
Please login or Register to submit your answer