Module (64%)
Section (38%)

Class variables

Class variables are defined within the class construction, so these variables are available before any class instance is created. To get access to a class variable, simply access it using the class name, and then provide the variable name.

class Demo: class_var = 'shared variable' print(Demo.class_var) print(Demo.__dict__)

Similarly to instance variables, class variables are shown in the class's __dict__ dictionary.

shared variable {'__module__': '__main__', 'class_var': 'shared variable', '__dict__': , '__weakref__': , '__doc__': None}

output


Code

class Demo:
class_var = 'shared variable'

print(Demo.class_var)
print(Demo.__dict__)
{{ dockerServerErrorMsg }} ×
{{ errorMsg }} ×
{{ successMsg }} ×