class Dog:
    num_legs = 4 # <- Переменная класса

    def __init__(self, name):
        self.name = name # <- Переменная экземпляра


jack = Dog('Джек')
jill = Dog('Джилл')

print(jack.name, jill.name)
print(jack.num_legs, jill.num_legs)
Dog.num_legs = 3
print(jack.num_legs, jill.num_legs)


# True way edit class variables
class CountedObject:
    num_instances = 0
    def __init__(self):
        self.__class__.num_instances += 1
162e1267cc8ad48fd285455eca25720328adfa09
<mask token>


class CountedObject:
    num_instances = 0

    def __init__(self):
        self.__class__.num_instances += 1

class Dog:
    <mask token>

    def __init__(self, name):
        self.name = name


<mask token>


class CountedObject:
    num_instances = 0

    def __init__(self):
        self.__class__.num_instances += 1

class Dog:
    num_legs = 4

    def __init__(self, name):
        self.name = name


<mask token>
print(jack.name, jill.name)
print(jack.num_legs, jill.num_legs)
<mask token>
print(jack.num_legs, jill.num_legs)


class CountedObject:
    num_instances = 0

    def __init__(self):
        self.__class__.num_instances += 1

class Dog:
    num_legs = 4

    def __init__(self, name):
        self.name = name


jack = Dog('Джек')
jill = Dog('Джилл')
print(jack.name, jill.name)
print(jack.num_legs, jill.num_legs)
Dog.num_legs = 3
print(jack.num_legs, jill.num_legs)


class CountedObject:
    num_instances = 0

    def __init__(self):
        self.__class__.num_instances += 1

class Dog:
    num_legs = 4 # <- Переменная класса

    def __init__(self, name):
        self.name = name # <- Переменная экземпляра


jack = Dog('Джек')
jill = Dog('Джилл')

print(jack.name, jill.name)
print(jack.num_legs, jill.num_legs)
Dog.num_legs = 3
print(jack.num_legs, jill.num_legs)


# True way edit class variables
class CountedObject:
    num_instances = 0
    def __init__(self):
        self.__class__.num_instances += 1