Created
May 11, 2022 09:08
-
-
Save linkdd/439e23a6b6d90e3b305c20f1516b55a7 to your computer and use it in GitHub Desktop.
Python Generators
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 my_generator(): | |
yield 1 | |
yield 2 | |
yield 3 | |
return 4 | |
gen = my_generator() | |
next(gen) # 1 | |
next(gen) # 2 | |
next(gen) # 3 | |
next(gen) # raise StopIteration(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment