self
is required in instance methods which pertain to editing the object. Without self
as the first argument, its just a class method, which does not pertain to the object. When you assign something to self.var such as
self.image = pg.image.load('spaceship.png').contert()
self.image is a class attribute. Each object is going to have a separate copy. Which doesnt matter here as there is only one player. But you can use self.image in any class method in that class without passing argumetns back and forth....or using global keywords, etc. You can also call that attribute by the object via
player.image
the dunder init method (or constructor) is the method that gets executed automatically when the object is created.
So doing
player = Player(my_args)runs the dunder init method.
Recommended Tutorials: