• Aucun résultat trouvé

A crash course on OOP in Python

N/A
N/A
Protected

Academic year: 2022

Partager "A crash course on OOP in Python"

Copied!
9
0
0

Texte intégral

(1)

Agent-Based Modeling (Master SIED)

Andrea G. B. Tettamanzi

I3S Laboratory – SPARKS Team

[email protected]

(2)

Unit 2

A Crash Course on

Object-Oriented Programming

in Python

(3)

Andrea G. B. Tettamanzi, 2020 3

Object-Oriented Programming

A programming discipline whereby a programmer defines

Not only data structure

But also the operations that may be applied to them

This way

A data structure become an object, which includes

Data, called attributes

Operations, called methods

The programmer may define relationships between the objects

(4)

Objects and Classes

MyClass attributes

methods

i.e., data

object1: MyClass instances of the class

i.e., operations, functions, procedures object2: MyClass

(5)

Andrea G. B. Tettamanzi, 2020 5

Heritage

Heritage is the characteristic of an object-oriented language whereby the objects of a class “inherit”

all the properties defined for the classes of a higher level:

Attributes

Methods

Constants

Historically, this is one of the most controversial

characteristics

(6)

Heritage

A

B

C

a

a

a

b

b

(7)

Andrea G. B. Tettamanzi, 2020 7

OOP in Python

Objects are the abstraction of data

All data in a Python program are represented by objects, including code

An object possesses:

An identity (= its memory address) : id()

A type (supported operations + possible values)

A value (mutable or immutable, depending on the type)

Each class and class instance possesses a name

space, implemented as a dictionary

(8)

Class Definition

class ClsName(cl1,cl2,cl3):

"""documentation"""

# block of statements, method definitions, etc.

Class name (an identifier)

superclasses from which this class inherits

def __init__(self,arg1,arg2):

"""documentation"""

# initialization of an instance.

self.arg1 = arg1 self.arg2 = arg2

(9)

Andrea G. B. Tettamanzi, 2020 9

Creating and Using Objects

instance = ClsName(arg1,arg2)

instance.method(x,y) instance.attribute

ClsName.class_attribute

Références

Documents relatifs

Keywords: discrete geometry, computer graphics, supercover, m-flat, discrete analytical object, arbitrary dimension..

In this note we recall some classical results on the structure of the subdifferential of first order one-homogeneous functionals, and we give new regularity results which extend

Inspired from the fact that nonlinear time-varying feedback gains lead to improved performance, we propose in this work to revisit DCAL control scheme by replacing the constant

It may be the subject or the direct object in a sentence and thus, can mean either 'who?' or 'whom?' You may also choose to use the longer forms: qui est-ce qui to ask 'who?', qui

67 ( لكشلا 5 ) هلاوملأ كنبلا ليصحت ةيلمع ريس : ردصملا : :ىلع دامتعلااب ةبلطلا دادعا نم رتمؤلما ،ةيرئازلجا كونبلا في ةيرامثتسلاا ضورقلا رطامخ ةرادإ

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des

Starting from a clean definition of what is a documentary database, we defined what is a subdatabase, the single type of our algebra and their operands which fit to

On the group of purely inseparable points of an abelian variety defined over a function field of positive characteristic... On the group of purely inseparable points of an