Objects can call methods, those methods are defined in classes.
Methods can modify all variables of an object. This is done with the self keyword.
Because methods can be called from an object (instance), they are sometimes called instance methods.
Related course: Complete Python Bootcamp: Go from zero to hero in Python 3
If you have a class Phone, you can create a new phone object (Nexus).
In this example the class has a method addContact. We call this method in the object, which changes the phones contact list.
nexus = Phone()
The class itself has the methods and variables:
Every object you create has unique variables. If you create 3 objects, all of them have their own unique variables.
In the example above, we create an object Nexus.
On this object we can call the methods call() and addContact(). Those methods are defined in the class, but change the objects variables.
In the next article we’ll discuss the self keyword.