+ 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

7th Jul 2019, 8:20 AM
Y AD Ù
Y AD Ù - avatar
1 Resposta
+ 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=' ')
7th Jul 2019, 9:31 AM
Lothar
Lothar - avatar