← 파이썬 처음부터
레슨 63 / 78 · 5 XP
워밍업: 카운터 워밍업
이론과 문제
기계 번역이에요. 아직 원어민이 검토하지 않았어요.
메서드는 self를 통해 객체의 데이터를 바꿀 수 있어요:
class Counter:
def __init__(self):
self.value = 0
def add(self):
self.value = self.value + 1
c = Counter()
c.add()
c.add()
print(c.value) # 2
과제. Counter 클래스의 add() 메서드를 완성하세요: 호출할 때마다 value가 1씩 늘어나요.