Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. % Programmation avec Python (chapitre 7)
  2. % Dimitri Merejkowsky
  3. #
  4. \center \huge Rappels sur les classes
  5. # Définition d'une classe
  6. Construire la classe`Counter` avec un attribut `count`:
  7. ```python
  8. class Counter:
  9. def __init__(self):
  10. self.count = 0
  11. ```
  12. # Instantiation
  13. Construire une nouvelle *instance* de `Counter`
  14. ```python
  15. >>> counter = Counter()
  16. >>> counter.count
  17. 0
  18. ```
  19. # Méthode
  20. Ajouter une méthode pour incrémenter le compteur:
  21. ```python
  22. class Counter:
  23. def __init__(self):
  24. self.count = 0
  25. def increment(self):
  26. self.count += 1
  27. ```
  28. # Apeller une méthode
  29. ```python
  30. >>> counter = Counter()
  31. >>> counter.count
  32. 0
  33. >>> counter.increment()
  34. >>> counter.count
  35. 1
  36. ```