← Quiz: Python OOP: all 15 questions
Quiz: Python OOP · Question 13 of 15
What does this print? (code)
What does this print?
class Counter:
total = 0
def __init__(self):
Counter.total += 1
a = Counter()
b = Counter()
print(Counter.total)
- A.0
- B.1
- C.2
- D.An error
Answer & explanation
Correct answer: 2
total is a class attribute shared by all objects, and init runs once per object.
Can you get the rest right without peeking?
Take the timed Quiz: Python OOP quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →