Files
Learn-Python-Programming-Th…/ch05/first.n.squares.py
T
adii1823 ef37ce0c4e ch05
2021-10-28 17:38:16 +05:30

13 lines
287 B
Python

# first.n.squares.py
def get_squares(n): # classic function approach
return [x ** 2 for x in range(n)]
print(get_squares(10))
def get_squares_gen(n): # generator approach
for x in range(n):
yield x ** 2 # we yield, we don't return
print(list(get_squares_gen(10)))