Created
May 3, 2012 22:27
-
-
Save ashwin/2590010 to your computer and use it in GitHub Desktop.
Generator function in Python
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
# Infinite sequence generator | |
def sequenceGen(): | |
i = 0 | |
while True: | |
yield i | |
i += 1 | |
g = sequenceGen() | |
print( next( g ) ) # 0 | |
print( next( g ) ) # 1 | |
print( next( g ) ) # 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment