Python Generator

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2021 Jul 23 7:5
Editor
Edited
Edited
2024 Jul 12 12:42

memory를 효율적으로 사용

  • next() 메소드를 통해 차례로 값에 접근할 때마다 메모리에 적재하는 방식
  • Lazy evaluation 즉 계산 결과 값이 필요할 때까지 계산을 늦추는 효과를
yield 있는 함수는 함수의 context포함한 generator 객체를 반환
generator object는 iterator 프로토콜을 제공해서 ierable함
제너레이터는 정해진 이터레이션이 끝나면 StopIteration Exception예외처리 해줘야
Python Generator Usages
 
 
 
 
 
 
 

Recommendations