This commit is contained in:
adii1823
2021-10-28 17:38:16 +05:30
parent ee641c189f
commit ef37ce0c4e
46 changed files with 524 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
# first.n.squares.manual.py
def get_squares_gen(n):
for x in range(n):
yield x ** 2
squares = get_squares_gen(4) # this creates a generator object
print(squares) # <generator object get_squares_gen at 0x10dd...>
print(next(squares)) # prints: 0
print(next(squares)) # prints: 1
print(next(squares)) # prints: 4
print(next(squares)) # prints: 9
# the following raises StopIteration, the generator is exhausted,
# any further call to next will keep raising StopIteration
print(next(squares))