17.3 또 하나의 예제
다음은 16.3 변경자(269쪽)의 increment를 메서드로 재작성한 버전이다.
# class Time: 정의 안쪽
def increment(self, seconds):
seconds += self.time_to_int()
return int_to_time(seconds)
이 버전은 time_to_int가 메서드로 작성되었다고 가정한 것이다. 또한, 이 메서드는 순수 함수이며 변경자가 아니다.
다음은 increment를 호출하는 방법을 보여준다.
>>> start.print_time()
09:45:00
>>> end = start.increment(1337)
>>> end.print_time()
10:07:17