Skip to content
CodeKruPro

Count how many objects of a class were created

QuizEasy-MediumPython only

A class attribute is a variable written in the class body and shared by all objects. Three objects of each class are created. What are Counter.count and Bad.count?

class Counter:
    count = 0
    def __init__(self):
        Counter.count += 1

class Bad:
    count = 0
    def __init__(self):
        self.count += 1
  • 3 and 0
  • 3 and 3
  • 0 and 0
  • 3 and 1

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in