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)

  1. A. 3
  2. B. 0
  3. C. 1
  4. 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

Exams that ask this topic