What is the difference between print and return?

. 1 min read

I often mentor students on their very first day of coding. The most frequent question beginners ask is “What is the difference between print and return?”

It is a surprisingly difficult question to answer. For a start, you can’t use any jargon, which is an incredibly hard habit to break. In my mind, print and return are defined in terms of other programming concepts such as functions. To make matters worse, students often start coding in an interpreter, which gives the strong impression that print and return are identical.

I have asked many developers to answer this question without using any technical words. Can you explain the difference between print and return without using any of these words?

  • access
  • assign
  • available
  • calculate
  • console
  • display
  • evaluate
  • execution
  • function
  • method
  • object
  • output
  • pass
  • program
  • result
  • save
  • scope
  • screen
  • send
  • statement
  • terminal
  • value
  • variable
  • write

And of course, the words “print” and “return” are not allowed. The answer “print prints and return returns” is most definitely not allowed.

In the first workshop, I usually explain variables before print and return. In a previous post, I explained a variable as analogous to a cardboard box. print is like asking your friend to open the box and yell out what is inside. return is like asking your friend to grab an item from the box, and give it back to you.

When we’re mentoring beginners, it’s important to try and link concepts to what the student already knows about.

Talking to machines is a weird new concept, and words like “function” or “STDOUT” don’t yet mean anything. However, the student probably knows what a box is.

As much as you can, try to link abstract programming ideas to everyday decisions and objects.

Photo by Vino Li on Unsplash.