Home Tutorials Python OOP Concepts Class Variables
Class Variables

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

🏋️ Test Yourself With Exercises

Take our quiz on Class Variables to test your knowledge.

Browse Quizzes »