Why always for loops are used with Generators in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why always for loops are used with Generators in python

https://code.sololearn.com/cMgYt4kw5sqm/?ref=app

10th Aug 2022, 1:50 PM
Tony Stark
Tony Stark - avatar
2 Answers
+ 1
You don't always have to use for loop with generators: def g(): yield 1 yield 2 yield 3 a = g() print(next(a)) print(next(a)) print(next(a))
11th Aug 2022, 6:55 PM
Seb TheS
Seb TheS - avatar
0
Seb TheS Well bruh can't we utilize the general within the print statement like this: print(g()) and also this give the name of the function/generator
12th Aug 2022, 5:07 AM
Tony Stark
Tony Stark - avatar