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.
 
 
 
 
 
 

713 B

% Programmation avec Python (chapitre 7) % Dimitri Merejkowsky

\center \huge Rappels sur les classes

Définition d’une classe

Construire la classeCounter avec un attribut count:

class Counter:
    def __init__(self):
        self.count = 0

Instantiation

Construire une nouvelle instance de Counter

>>> counter = Counter()
>>> counter.count
0

Méthode

Ajouter une méthode pour incrémenter le compteur:

class Counter:
    def __init__(self):
        self.count = 0

    def increment(self):
    	self.count += 1

Apeller une méthode

>>> counter = Counter()
>>> counter.count
0
>>> counter.increment()
>>> counter.count
1