iterator
: next()메소드를 이용해 데이터에 순차적으로 접근이 가능한 객체
yield 구문
def create_gen():
alist = range(1, 4)
for x in alist:
yield x
my_generator = create_gen()
print(my_generator)
for n in my_genorator:
#결과
#<generator object create_gen at 0x7fc02986d3c0>
#1
#2
#3
# 제너레이터 두번 실행
def create_gen():
alist = range(1, 4)
for x in alist:
yield x
my_generator = create_gen()
print(my_generator)
for n in my_generator:
print(n)
print("-----------------")
for n in my_generator:
print(n)
# 실행 결과
#<generator object create_gen at 0x7f91de9d43c0>
#1
#2
#3
#-----------------