return (match.group() for match in RE_WORD.finditer(self.text))
[예제
17
-
8
]과
__iter__()
메서드만 다르다. 여기서는 제너레이터 함수가 아니라(
yield
문
이 없다), 제너레이터를 생성해 반환하는 제너레이터 표현식을 사용한다. 실행 결과는 [예제
17
-
8
]과 똑같다.
__iter__()
메서드의 호출자가 제너레이터 객체를 받는다.
제너레이터 표현식은 편리 구문이다. 제너레이터 함수로 대체할 수 있지만, 때로는 제너레이터
표현식이 더 편리하다. 다음 절에서는 제너레이터 표현식을 사용하는 방법을 알아보자.
17
.
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.