본문 바로가기
언어 정리/python_lib,일급함수

5_iter_gen_yield기반coroutine 함수기반정리

by 알 수 없는 사용자 2022. 6. 15.
  • 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을 내지 않고, 정해진 반환값을 전달해주는 역할을 해줌

'언어 정리 > python_lib,일급함수' 카테고리의 다른 글

pylint - 해당 lib로 코드점검 기능 사용  (0) 2022.07.20
4_Asyncio,coroutine  (0) 2022.06.15
3_yield기반의 coroutine 코루틴  (0) 2022.06.14
2_generator  (0) 2022.06.13
1_iterator  (0) 2022.06.12

댓글