언어 정리/python_lib,일급함수
5_iter_gen_yield기반coroutine 함수기반정리
알 수 없는 사용자
2022. 6. 15. 00:20
- Iterator
- __iter__() : iterator object 리턴
- __next__() : 호출될 때 마다 다음 값을 리턴
- generator
- yield : generator 함수를 멈추고, 값을 next(x)를 호출한 함수로 전달
- next() : generator의 yield를 만날 떄까지 실행시키고 값을 반환받음
- yield 기반 coroutine ( 사실 generator와 동일 )
- yield : coroutine 함수를 멈추고, 값을 next(x)를 호출한 함수로 전달
- next() : coroutine 의 yield를 만날 떄까지 실행시키고 값을 반환받음
- send(y) : caller가 coroutine 의 yield 부분에 y값을 전달할 수 있음 + next와 동일작동
- throw(type, value, traceback) : caller가 coroutine 의 yield 부분에 exception 전달
- close() : thorw를 이용하여 GeneratorExit exception을 coroutine에게 전달
- yield from : caller에 sub-coroutine 값을 주고 받게함
- return : coroutine의 순환이 끝났어도 StopIteration exception을 내지 않고, 정해진 반환값을 전달해주는 역할을 해줌