Class Variables
Introduction to OOP's
Class
Object
Constructor
Instance Variables
Class Variables
Instance Methods
self Keyword
Encapsulation
Public Members
Protected Members
Private Members
Inheritance
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Hybrid Inheritance
super() Function
Polymorphism
Method Overriding
Duck Typing
Abstraction
Abstract Class
Abstract Method
Class Method
Static Method
Special Methods
_str_ Method
Operator Overloading
Composition
Aggregation
Association
Method Resolution Order
Object Class
issubclass() and isinstance()
Property Decorator
Setter Method with @property
Destructor
Inner Class
Complete Mini Example
Class Variables
5. Class Variables
Class variables are shared by all objects of a class. They are useful when the same value should belong to the class itself instead of each instance.
Syntax
class ClassName:
variable = value
Example
class School:
school_name = "ABC School"
s1 = School()
s2 = School()
print(s1.school_name)
print(s2.school_name)
Output
ABC School
ABC School
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Class Variables to test your knowledge.
Browse Quizzes »