Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created May 29, 2020 01:39
Show Gist options
  • Save ZhouYang1993/b88f9ff4d882dc8a176cb34c6361f6d8 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/b88f9ff4d882dc8a176cb34c6361f6d8 to your computer and use it in GitHub Desktop.
def my_generator(maximum):
n = 0
while n < maximum:
n += 1
yield n
return 'Done'
g = my_generator(maximum=5)
next(g)
# 1
next(g)
# 2
next(g)
# 3
next(g)
# 4
next(g)
# 5
next(g)
# Traceback (most recent call last):
# File "/usr/lib/python3.6/code.py", line 91, in runcode
# exec(code, self.locals)
# File "<input>", line 1, in <module>
# StopIteration: Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment