Last active
December 27, 2019 16:37
-
-
Save edenau/d23b71ff473720ae19fd4514f2232bdb to your computer and use it in GitHub Desktop.
Python Generator
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(n): # an infinite sequence generator that generates integers >= n | |
while True: | |
yield n | |
n += 1 | |
G = gen(3) # starts at 3 | |
print(next(G)) # 3 | |
print(next(G)) # 4 | |
print(next(G)) # 5 | |
print(next(G)) # 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment