Repaso
EspaƱol
PythonFoundationsPY-69

What is the difference between print and return in a function?

Options

  1. They are the same: both show text and also end the function
  2. print shows text on screen; return sends a value back to the caller (Correct option)
  3. return shows text on screen; print ends the function now
  4. print saves a value in a file; return clears the screen

Answer

print shows text on the screen; return sends a value back to the code that called the function so it can be used

Why

A very common beginner confusion.

print(x) only displays x for a human to read. The program cannot use it afterwards.

return x hands x back to the caller: total = add(2, 3) stores 5 in total.

If a function only prints and does not return, total would be None.

Remember

print = show. return = give back.

Key terms

Practice this question in Repaso