What is the expected output of the following code?
class A: A = 1 def __init__(self): self.a = 0 print(hasattr(A, 'a'))
- 1
- 0
- True
- False
Explanation: The hasattr() function can also operate on classes to find out if a class has a particular class variable available. In this case, class A has the class variable A, not a, which is why the function will return False.
More Questions: Python Essentials 2 (PE2) Course Final Test
Please login or Register to submit your answer