What does the 'yield' keyword do?

If the compiler detects the yield keyword anywhere inside a function, that function no longer returns via the return statement. Instead, it immediately returns a lazy 'pending list' object called a generator. A generator is iterable. iterable is anything like a list or set or range or dict-view, with a built-in protocol for visiting each element in a certain order. So basically, a function with 'yield' is not a normal function anymore, instead it becomes a generator . Every time the code is executed to "yield", it returns the right side of "yield", then it continues to loop the code.
def makeSqure(n): i = 1 while i < n: yield i * i i += 1 print(list(makeSqure(5)))
output
[1, 4, 9, 16]
In the example above, the "yield" statement suspends function's execution and sends a value back to caller in each iteration, but retains enough state to enable function to resume where it is left off. When resumed, the function continues execution immediately after the last yield run.