How would you define a class variable that is shared among all instances of a class in Python?

  • As a global variable outside the class
  • As a local variable inside a method
  • Inside the constructor method using self
  • Outside of any method at the class level
In Python, you define a class variable outside of any method, directly within the class, and it is shared among all instances of the class. It is accessible as ClassName.variable_name.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *