From 01e0643dd2c393bd2c9aab7d412579bc46f60001 Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Fri, 1 Mar 2019 10:50:03 +0100 Subject: [PATCH] Update python-07.md --- sessions/python-07.md | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 sessions/python-07.md diff --git a/sessions/python-07.md b/sessions/python-07.md new file mode 100644 index 0000000..9b12b3b --- /dev/null +++ b/sessions/python-07.md @@ -0,0 +1,55 @@ +% Programmation avec Python (chapitre 7) +% Dimitri Merejkowsky + + +# + +\center \huge Rappels sur les classes + + +# Définition d'une classe + +Construire la classe`Counter` avec un attribut `count`: + +```python +class Counter: + def __init__(self): + self.count = 0 +``` + + + +# Instantiation + +Construire une nouvelle *instance* de `Counter` + +```python +>>> counter = Counter() +>>> counter.count +0 +``` + +# Méthode + +Ajouter une méthode pour incrémenter le compteur: + +```python +class Counter: + def __init__(self): + self.count = 0 + + def increment(self): + self.count += 1 + +``` + +# Apeller une méthode + +```python +>>> counter = Counter() +>>> counter.count +0 +>>> counter.increment() +>>> counter.count +1 +```