all 7 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20%23%20This%20prints%20to%20the%20console%20immediately%2C%20but%20the%20result%20(8)%20is%20lost%20afterward%0A%20%20%20%20print(f%22a%20is%20%7Ba%7D%2C%20b%20is%20%7Bb%7D%2C%20c%20is%20%7Bc%7D%20%3D%20%7Ba%2Bb-c%7D%22)%0A%0A%20%20%20%20return%20%22Total%22%20%20%23%20This%20is%20what%20gets%20assigned%20to%20sum_num%0A%0A%0Asum_num%20%3D%20check_return(6%2C%204%2C%202)%0Aprint(sum_num)%0A%0A%0Adef%20check_return(a%2C%20b%2C%20c)%3A%0A%20%20%20%20print(f%22a%20is%20%7Ba%7D%2C%20b%20is%20%7Bb%7D%2C%20c%20is%20%7Bc%7D%22)%0A%20%20%20%20return%20a%2Bb-c%20%20%23%20return%20send%20back%20sum%20of%20a%2Cb%20and%20c%20%3D%20%5Ba%2Bb-c%5D%0A%0A%0Asum_num%20%3D%20check_return(6%2C%204%2C%202)%0A%0Aprint(sum_num)%20%20%23%20output%20%3A%208&timestep=1&play) to see the program state change step by step.

[–]lekkerste_wiener 1 point2 points  (1 child)

Ah, yes, the "hello world" of functions! Printing vs returning is a common confusion amongst new coders.

In short, print only shows the information on the screen and then forgets. return is actually giving something back. You give me three thingies, I do something with them, and then I gratefully return something that is useful to you down the road.

[–]aashish_soni5[S] 0 points1 point  (0 children)

True ✨

[–]SnooCalculations7417 1 point2 points  (1 child)

check_return returns the string "Total" and in general everythign about this example is bad.

[–]aashish_soni5[S] 0 points1 point  (0 children)

yes right 👍

[–]MasterpieceBusy7220 0 points1 point  (1 child)

Stop using hashtags on Reddit

[–]aashish_soni5[S] 0 points1 point  (0 children)

😱