What is the point of self.x = x?

class Car:

def __init__(self,make,model,year):
    self.make=make
    self.model=model
    self.year=year
#---snipped code 
  • Why can it not be make = self.make i.e. the reverse?
  • What is exactly the point of self.make = make assignment?

Answer

The variable self refers to the current object and self.make is an attribute of this object. The variable make is just a local variable whose scope ends at the end of the __init__ method. The assignment thus serves to save this variable into the object so that its other methods can refer to it, vaguely like a global variable except it’s local to this class, and each instance of the class (each object) has its own private copy.