
Virgilio D. answered 05/16/18
Tutor
New to Wyzant
Senior Software Engineer Specializing in Python.
yield returns an element from an object that you can iterate with. the benefit is when it is used in a function, the element is returned to the caller, the function seems to be suspended as of this moment, and execution can be continued because the execution context has been kept and the interpreter knows where to continue. by the way the function is now a "generator". a.next() will return the first item, a.next() again will return the second item, etc etc etc, you can stop anytime. with the list, all the elements are loaded at once into memory, this is not the case with generators. :)