Skip to content

Instantly share code, notes, and snippets.

@JackInTaiwan
Created October 20, 2019 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackInTaiwan/3e3c0c20d595c6f89adc5fce103e1ce9 to your computer and use it in GitHub Desktop.
Save JackInTaiwan/3e3c0c20d595c6f89adc5fce103e1ce9 to your computer and use it in GitHub Desktop.
python_iteration_5.py
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