Everything in python is an object. A class is a blueprint of an object, to create a class you use
Myclass:
After creating a class, you will call the class feature or method by assigning it to an object
E.g perrie = Myclass()
To fully understand class, you need to understand the __init__
function, all class have an init function which is executed when a class is being initiated
Method: are function inside a class
The self parameter: This is a reference to the current instance of a class and it allows you to access all variable in a class
Class variable: are variable inside a class, they belong to the class
Instance variable: are variable inside a class that belongs to the instance.
Let's use a real-life analogy to explain class (Insight got from Quora)
Example of a Class in real life:
Class in real life is your: Mother.
Initialization in real life is your: Birth Process. (Init function)
Object in real life is: You.
Another object in real life is: Your sister.
We can say you and your sister are instances of the class, in real life means: You and your sister are the children of your mother. (Self.debby, self.wale)
Class Constructor in real life would be: What makes your genes. (What's inside def init function)
Class Methods in real life are: What your mother teach you to do, like [eat, order your bed, take a bathe etc…]. (def eat_well(): function)
Object Attributes in real life are: What differ you from others people, like [your name, eye color, skin, your fingerprint, your accent]. (print attribute of a method)