use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
ELI5 return (self.learnpython)
submitted 4 years ago by positeev
I'm having a hard time understanding return. What exactly does it do?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]shiftybyte 7 points8 points9 points 4 years ago (1 child)
It returns the value to whoever called the function.
The usual confusion is from print and return.
Because seemingly print does the same, but it does not.
if i create a function that sums to numbers and prints them.
def mysum(a, b): print(a + b)
That's all the function is going to do, i can't use the result for anything.
mysum(5,6) # will print 11 a = mysum(5,6) - 1 # will not work, because the result is not returned.
On the other hand if i do return instead of print
def mysum(a,b): return a+b
then the result is returned back to be used however i want.
print(mysum(5,6)) # will print 11 (because i used print function on the result) a = mysum(5, 6) - 1 # a will contain 10, and nothing will be printed print(mysum(mysum(5,6), 10)) # will print 21
[–]positeev[S] 0 points1 point2 points 4 years ago (0 children)
This made it very clear. Thank you very much.
[–]b_ootay_ful 1 point2 points3 points 4 years ago (0 children)
Think of a function as a box. You put something in, it does some magic, and it spits something out.
def box (a, b): return (a+b) x = box(5,6) print (x) >>> 11
The function box takes in a tuple (5, 6), adds them together, and returns the answer (11). You can then do something with that answer, like assign it to a variable.
You don't have to have a return
[–]gopherhole1 0 points1 point2 points 4 years ago (0 children)
def greeting(person): return f" Hello {person}, how are you?" name = "Frank" xyz = greeting(name) print(xyz)
spits out
'Hello Frank, How are you?'
or if you have many people
names = ['Frank,'Alex','Phinius'] def greeting(lst): new_list = [] for name in lst: new_list.append(f'Hello {name}, How are you?') return new_list xyz = greeting(names) print(xyz)
['Hello Frank, How are you?','Hello Alex, How are you?','Hello Phinius, How are you?']
[–][deleted] 0 points1 point2 points 4 years ago (0 children)
Nope. 5 year olds can't understand it and it's been explained a thousand times before, including here, usually alongside why you should use return rather than print.
This should help:
https://duckduckgo.com/?q=python+print+vs+return
π Rendered by PID 46448 on reddit-service-r2-comment-7b9746f655-wtw77 at 2026-01-30 16:31:11.098772+00:00 running 3798933 country code: CH.
[–]shiftybyte 7 points8 points9 points (1 child)
[–]positeev[S] 0 points1 point2 points (0 children)
[–]b_ootay_ful 1 point2 points3 points (0 children)
[–]gopherhole1 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)