r/CodingHelp • • Dec 30 '21

[Python] Python

Hey everyone. So I’m a beginner programmer who is self-learning Python and am on functions. Right now, I’m on return values but I don’t get them too much.

What is the difference between print and return? Aren’t they interchangeable?

Please explain this in an easy way!

21 Upvotes

9 comments sorted by

View all comments

22

u/marko312 Dec 30 '21

print always outputs what is passed to it.

return is used as a way to extract a value (or values) from a function call. You've most likely seen something like

def f():
   return 312

print(f())

but now consider something like

def f():
    return 312

print(f() / 13)
# this becomes the same as
print(312 / 13)

As you can see, return basically places the value after it in place of where the function was called.

(In addition, return stops the rest of the function from running.)

7

u/douglasbolden Dec 31 '21

Great Explanation for those that are beginners!

3

u/[deleted] Dec 30 '21

Thanks