져오는 대신 실행 도중에 항목을 생성하는 경우에도 유용하게 사용할 수 있다. 예를 들어 내
장 함수
range()
는 정수로 구성된 유한
bounded
등차수열
arithmetic
progression
(
AP
)을 생성하며,
itertools.count()
함수는 무한
boundless
등차수열을 생성한다. 그런데 정수만 아니라 임의
자료형의 숫자로 구성된 등차수열을 생성해야 한다면 어떻게 해야 할까?
[예제
17
-
11
]은 잠시 후에 설명할
ArithmeticProgression
클래스를 콘솔에서 테스트한 결
과를 보여 준다. 이 예제에서 사용한 생성자 시그너처는
ArithmeticProgression(begin,
step[, end])
다.
range()
함수가 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.