on-internet
← Community

What is the purpose of the return statement? How is it different from printing?

Stack Overflow ·

What does the return statement do? How should it be used in Python? How does return differ from print? See also Often, people try to use print in a loop inside a function in order to see multiple values, and want to be able to use the results from outside. They need to be returned, but return exits the function the first time. See How can I use `return` to get back multiple values from a loop? Can I put them in a list?. Often, beginners will write a function that ultimately prints something rather than returning it, and then also try to print the result, resulting in an unexpected None. See Wh

Comments

Sign in or sign up to comment and upvote.

No comments yet.