Understand Python “yield”, An interrupt, A trap, A scissor

Andrew Zhu (Shudong Zhu)
Geek Culture
Published in
4 min readAug 2, 2021

--

Some said “yield” is similar to the usage of “return”, the answer could be both yes and no. But one thing is certain: yield is not return.

What is yield in Python?

The keyword “yield” working like a scissor cut the program into two parts.

The keyword “yield” working like an interrupt in OS, yield will return the control of the program back to the caller.

The keyword “yield” not only gives control back to the caller, but it can also…

--

--