-2

Can someone explain the difference between Return values and Print.

If in a Python function and I want to return a value does it have to be a number or could it be anything? Please provide example,

B Thind
  • 21
  • 4
  • 1
    Does this answer your question? [How is returning the output of a function different from printing it?](https://stackoverflow.com/questions/750136/how-is-returning-the-output-of-a-function-different-from-printing-it) – adam Jun 15 '20 at 13:44

1 Answers1

0

I believe return() is specific to being used within functions, and that you can include anything printable as an argument. For example,

x = 7
return(x)

would return an error, whereas

x = 7
print(x)

or

def printx(X):
   return(X)

should be fine. Specifically, return() is used to end the execution of a function; nothing after a return() statement will be executed. More information can be found here: https://www.geeksforgeeks.org/python-return-statement/#:~:text=Python%20return%20statement,return%20statements%20are%20not%20executed.

Amelia Henkel
  • 60
  • 1
  • 1
  • 6