Python Forum

Full Version: Confusion regarding 'self' while creating instance
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi people

I am a total noob to programming and trying to learn python from "Python Crash Course".

I am currently working on making the "Alien Invasion" game.

The book tells me to create instances of two classes (from different files) as follows:

self.settings = Settings()
self.ship = Ship(self)
Why do I have to use 'self' for one and not for the other?

Thanks
self refer to class object.
Settings is probably data that is read. Doesn't effect the current object.
Ship needs to read data from current object. It need a way to point to it. So you pass self.

Source code will tell you a lot more.
Without seeing Ship class. Can't tell you what it actually doing.
Thanks. I get it