A Example of Python Class This example includes class definition, constructor function, From the code , we can see that after instantiate object, it
construct an object from that class definition • Similar to a “list” Python defines what a list is the data (attributes) and the code (behaviors) that
Example Following is the example of a simple Python class − When the above code is executed, it produces the following result −
Le programme principal s'en trouve grandement simplifié # -*- coding: utf -*- #appel du module import ModulePersonne as MP #instanciation
Python, a class's constructor is always named __init__() For example, the following code defines a class for storing information about backpacks
Python passes it for you automatically Defining a method: Calling a method: (this code inside a class definition ) def set_age(self, num):
Python supports OOP through the provision of classes • Terminology Note: the entire class code block (i e any attribute and Defining a class in
code • create instances of the object type • do operations with them author of class definition may change data attribute variable names
that are shared by all objects of a class once in the class definition, it leaves the job to look up the class to Python and your code will be more