Understanding Independence Inside Python

I fully understand what is being transmitted selfin this example. I am very confused about how it is transmitted selfinternally. Can someone help me understand?

class Cars:

    def __init__(self, model, engine, doors):

        self.model = model
        self.engine = engine
        self.doors = doors

tesla = Cars('Model S', 'Electric', 'Four door')
ford = Cars('Mustang', 'v8', 'Two door')
+4
source share
1 answer

There are many steps that beginner's tutorials do not cover, so I will try to be concise but thorough. I will try to be accurate in my terminology, so you can view all the sections that you are not clear about.

, Python . . , , , instance, , , , self. , Cars method start(self) __init__, tesla.start " " , , tesla self Cars.start. , tesla.start . .

: __call__ , . , , , (). , tesla = Cars(...). Cars - , , . , self __init__.

-, Python object , , , .. classes. , metaclass. metaclasses , , , - type: 99% 1 , type. type __call__, , Cars(...), Cars type.

type.__call__(Cars, ...) . Cars.__new__(Cars, ...). , tesla ford - . , __new__ Cars, Cars.__init__(self, ...), self - , .

, self __init__. , , .


. , . Stack Exchange (SO ) Python 3, .


1 , , , .

+7

Source: https://habr.com/ru/post/1695223/


All Articles