What is the difference between break and return?


#1

Question

What is the difference between break and return?

Answer

break is used to prematurely end a loop, like we have done a few times throughout this lesson. return is only usable in functions and returns a value to wherever the function was called in the program. If you try using return outside of a function you will get an error.


FAQ: Learn Python- Loops - For / else