+ 2
Here...why we cant get the countdown when we just do print (countdown ())
And why converting it into the type of lists...gets the output. Does a generator alwys needs to be iterated or can we print it just lyk how we print a function.? https://code.sololearn.com/cYYgb84iRLTU/?ref=app
1 Odpowiedź
+ 6
you are right: a generator object needs to be iterated. see possibilities to output:
def countdown():
i=5
while i > 0:
yield i
i -= 1
print()
print(list(countdown()))
print(*countdown())
for item in countdown():
print(item, end=' ')