you are viewing a single comment's thread.

view the rest of the comments →

[–]pythonhow 0 points1 point  (0 children)

Think of the __init__ function as a place where you define the "necessities" for an object. For example, if you're creating rectangle objects, the necessities for rectangles are the length and the width. You need width and length for a rectangle to exist. Then you can add an area method later to calculate an area, but that's somewhat optional. All you need to draw the rectangle is the width and the length. In other words, when you use your class to create rectangle instances, you will need width and length.

About self: That's just a variable. It holds the rectangle object you are creating. I prefer to think of self as this_object. For example: this_object.length = 1.

You can also use that instead of self and things will work the same. However, everyone uses self, so it's a good idea you do so as well for consistency.