Created
May 29, 2020 01:39
-
-
Save ZhouYang1993/b88f9ff4d882dc8a176cb34c6361f6d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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