print and return
2026-06-29
I am asked this question quite often, but I can never seem to give an answer I am satisfied with.
Python students often conflate print and return despite the terms being, in my opinion, unrelated. This conflation is mostly due to how we use Jupyter notebooks to teach Python, where outputs from print and the last value in any given cell are both rendered. It does not help that Python's name for the print function describes what beginners see, not what the function actually does.
print pushes a textual representation of data you give it to a data stream called standard output (stdout). The reason why this causes text to display on the screen is because, by default, your terminal screen (or Jupyter) will capture and display stdout. Typically, when you push data into stdout, you want it to leave the program entirely.
return only exists in the context of a function, and it causes a function call to terminate and to evaluate to the value of a given expression. A function can be thought of as a program within a program. A return statement pushes the expression given to it outside the function but not outside the entire program. The value given to return can thus be captured, bound, and used by the rest of the program. If a function finishes without hitting a return statement, that function call will evaluate to None.