25개 이상의 토픽을 선택하실 수 없습니다.
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- % 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
- ```
|