Created
February 23, 2021 00:58
-
-
Save iamjjanga-ouo/e97f155df7e5b211750e45d4a780d6d0 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 get_natural_number(): | |
n = 0 | |
while True: | |
n += 1 | |
yield n | |
get_natural_number() # <generator object get_natural_number at 0x10d3139d0> | |
g = get_natural_number() | |
for _ in range(0, 100): | |
print(next(g)) # 1 ~ 100까지 출력 |
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 generator(): | |
yield 1 | |
yield 'string' | |
yield True | |
g = generator() | |
print(next(g)) # 1 | |
print(next(g)) # 'string' | |
print(next(g)) # True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment