According to the explanations of https://www.codecademy.com/courses/learn-python-3/lessons/data-types/exercises/class-variables a class variable is a variable that’s the same for every instance of the class.
Here is a piece of code
class SomeClass: def __init__(self): self.foo_num = 1 self.foo_list =  bar_num = 2 bar_list =  sc1 = SomeClass() sc1.foo_list.append(1) sc1.bar_list.append(2) sc1.bar_num = 3 sc2 = SomeClass() sc2.foo_list.append(10) sc2.bar_list.append(20) sc2.bar_num = 30 print(sc1.foo_list) print(sc1.bar_list) print(sc1.bar_num) print(sc2.foo_list) print(sc2.bar_list) print(sc2.bar_num)
The output of the code is
It looks like when I am changing the Class variable list (bar_list) this is reflected in both object sc1 and sc2, while bar_num is behaving like an instance variable. Why is this happening?