Last active
July 5, 2021 12:58
-
-
Save hrchu/9e89c735fb5e77591626478bd901393e to your computer and use it in GitHub Desktop.
Python generator simple usage
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 gen(): | |
a = range(5) | |
for x in a: | |
yield x | |
x = gen() # instanlize | |
x.__next__() # get next | |
Out[36]: 0 | |
next(x) # alternative way | |
Out[37]: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment