culTest

    One of the 50 questions in this topic

    How much do you know about Python?

    What is a class variable in Python?

    Answers

    A variable defined inside a class but outside any methodCorrect
    A variable that can only contain classes
    A local variable in a class method
    A variable that changes type dynamically

    A class variable is defined inside a class but outside any method, and is shared by all instances. It is accessed as Class.variable or self.variable (although the latter can create an instance variable if modified). They are useful for attributes that must be common to all objects, such as counters, settings, or constants. Modifying it affects all existing and future instances.