source: http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained The Python yield keyword explained To understand what yield does, you must understand what generators are. And before generators come iterables. Iterables When you create a list, you can read its items one by one, and it's called iteration: >>> mylist = [ 1 , 2 , 3 ] >>> for i in mylist : ... print ( i ) 1 2 3 Mylist is an iterable. When you use a list comprehension, you create a list, and so an iterable: >>> mylist = [ x * x for x in range ( 3 )] >>> for i in mylist : ... print ( i ) 0 1 4 Everything you can use "for... in..." on is an iterable: lists, strings, files... These iterables are handy because you can read them as much as you wish, but you store all the values in memory and it's not always what you want when you have a lot of values. Generators Generators are iterators, but you can ...