OK, perhaps we need to start over from scratch. What you need to understand is that an object is a model of something. It can be something real, like a car or a person, or something conceptual, like a list or a dictionary (I use those examples because, as it happens, lists and dictionaries are objects in Python). The point is that the object captures or encapsulates the properties of the thing it is modeling, its current state, and its potential behavior. The properties and state are described by variables that are part of the object, called instance variables, and the behavior is described by functions which are bound to the object, called instance methods.
A class is a description of an object, a sort of template or mold for making new objects. It defines both the instance variables of the object, and the methods the object can perform. It works by providing a way of creating a new object - the __init__()
method, also known as the constructor or c'tor. The c'tor primary job is to set the initial values of the object's instance variables. It can do anything that you can do in any other method, but it should initialize the instance variables in some way.
In Python the first argument of any instance method is the object itself, which by convention is named self
. This is true of the __init__()
method as well, even though it is actually not an instance method per se (it is a …