What is the difference between return and print in python?

Sometimes the tutorial teaches to use ‘return’ after a function is created. I am not sure what it does.

I think it’s time someone introduced you to https://www.google.com


And also, if you think about what functions do, that should let you make a pretty good guess about what return does.

def two_plus_two()
This one will print to your screen 4

def two_plus_two()
This one does 2+2 and just throws away the 4

def two_plus_two()
  return 2 + 2
This one hands the value 4 back to the caller
I can use that 4 in other parts of my program now

i.e. 4 + two_plus_two() = 8
or if (two_plus_two > 3)

After looking a bit using google: Print vs Return. Hope it helped you.

You don’t always want to print everything on the screen.

def plus_two(integer):
   x = integer + 2
  return x

After you use this function:


The value of x will be saved in the memory and you can use it for later operations.

1 Like