길/Python
Generators
7he8oy
2021. 2. 12. 14:42
def numbers(x):
for i in range(x):
if i % 2 == 0:
yield i
print(list(numbers(11)))
위 코드는 0 ~ 10 사이의 짝수를 리스트로 만들어 프린트하게 된다.
Generator의 이점은 메모리를 적게 차지하는 것이라고 한다.