ProgrammingVery hardIBM · Deloitte · Product Company SDE
What does the following Python 3 code print? class A: count = 0 def __init__(self): A.count += 1 a1 = A(); a2 = A(); a3 = A() print(A.count)
- A. 3
- B. 0
- C. 1
- D. 9
Correct answer: A. 3
Each constructor call increments the shared class attribute A.count by 1; three instances give 3.
More Python Programming questions
- What does the following Python 3 code print? print(round(2.5), round(3.5), round(2.675, 2))
- What does the following Python 3 code print? print(0.1 + 0.2 == 0.3)
- What does the following Python 3 code print? print(bool([]), bool({}), bool(()), bool(0.0), bool("0"))
- What does the following Python 3 code print? print([] == False, [] is False)
- What does the following Python 3 code print? x = [1, 2, 3] y = [1, 2, 3] print(x == y, x is y)
- What does the following Python 3 code print? print(2 10, 2 0.5, 10 // 3, -10 // 3, 10 % 3, -10 % 3)