Bird
0
0

What is a class attribute in Python?

easy📝 Conceptual Q1 of 15
Python - Classes and Object Lifecycle
What is a class attribute in Python?
AA function outside the class
BA variable unique to each instance of a class
CA variable shared by all instances of a class
DA method inside a class
Step-by-Step Solution
Solution:
  1. Step 1: Understand class attributes

    A class attribute is defined inside a class but outside any method and is shared by all instances.
  2. Step 2: Differentiate from instance attributes

    Instance attributes are unique to each object, while class attributes are common to all.
  3. Final Answer:

    A variable shared by all instances of a class -> Option C
  4. Quick Check:

    Class attribute = Shared variable [OK]
Quick Trick: Class attributes belong to the class, not instances [OK]
Common Mistakes:
  • Confusing class and instance attributes
  • Thinking methods are attributes
  • Assuming attributes are always unique per object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes