Generators | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Generators

Can we say that yield is similar to return function only it do not stop the loop as return do ?

24th Jan 2017, 8:40 AM
Aditya Kumawat
Aditya Kumawat - avatar
1 Answer
+ 3
Yes, that's what yield do. Everything you yield something you're adding that to a range of things. Range function itself in python3 is considered as a generator {in python2 is considered as a list}. Remember, giant lists will let you out of memory, Giants yields will let you out of time!!
24th Jan 2017, 10:26 AM
Krec
Krec - avatar