Question 8
Back to Exercise
What is the output of the following Python program?
class A:
def __init__(self):
self.__secret = 1
self._hint = 2
a = A()
print(hasattr(a, "__secret"), a._A__secret, a._hint, sorted(vars(a)))
- A True 1 2 ['__secret', '_hint']
- B False 1 2 ['_A__secret', '_hint'] Correct
- C False 1 2 ['__secret', '_hint']
- D AttributeError
Correct Answer: Option B
__secret is stored as _A__secret; a single underscore name is stored as written.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!