def num_coroutine():
total = 0
while True:
print('before yield')
x = (yield total)
total += x
print('after yield')
print(x)
except GeneratorExit:
print('close coroutine')
co = num_coroutine()
print('total',next(co))
print('total', co.send(int(input('put int:'))))
print('total', co.send(int(input('put int:'))))
print('total', co.send(int(input('put int:'))))
co.close()
'python' 카테고리의 다른 글
conda 가상환경(virtual environment)를 Pycharm에서 설정하는 방법 (0) | 2021.04.17 |
---|---|
변환, 정렬, packing unpacking 간단 예제 (0) | 2020.01.29 |
클래스 변수, 인스턴스 변수 (0) | 2020.01.20 |
형변환 연습 (0) | 2020.01.16 |
python 가상환경 설정 (0) | 2020.01.02 |