Created
October 20, 2019 06:26
-
-
Save JackInTaiwan/3e3c0c20d595c6f89adc5fce103e1ce9 to your computer and use it in GitHub Desktop.
python_iteration_5.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generator_func(value=0): | |
while value < 10: | |
value = yield value | |
value += 1 | |
generator = generator_func() | |
print('step 1') | |
print(next(generator)) | |
print('step 2') | |
print(generator.send(1)) | |
print('step 3') | |
print(generator.send(7)) | |
print('step 4') | |
print(generator.send(10)) | |
# step 1 | |
# 0 | |
# step 2 | |
# 2 | |
# step 3 | |
# 8 | |
# step 4 | |
# Traceback (most recent call last): | |
# File "/Users/jackcheng/Programming/python/notes/notes_11.py", line 106, in <module> | |
# print(generator.send(10)) | |
# StopIteration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment