programming with python • Introduces Python's special methods to realize class definition, inheritance, multiple inheritance, accessibility,
While with modules, you have only one with the entire program Objects are like Mini-imports A class is like a mini-module and you can import in a similar way
However, here is small introduction of Object-Oriented Programming (OOP) to bring you at speed: Following is the example of a simple Python class:
particular class • Attributes may be public or private (although due to their specific implementation, they are not truly private in Python)
Python is an object oriented programming language Example: Create a class named MyClass, with a property named x: class MyClass: x = 5 print(MyClass)
Python passes it for you automatically Defining a method: Calling a method: (this code inside a class definition ) def set_age(self, num):
•Object Oriented Programming in Python Python Example (I) 15 import random class Die(object): # derive from object for new style classes
When an instance of a class is created, the class constructor func on is automa cally called • The constructor is always named __init__() • It contains code
class Personne: """Classe Personne""" #constructeur def __init__(self): #lister les champs self nom = "" self age = 0 self salaire = 0 0 #fin constructeur