What exactly is the return function ? | Sololearn: Learn to code for FREE!

+5

What exactly is the return function ?

I wanna say_ How is return function different from print function ?

4/28/2021 2:47:20 AM

M Umer

11 Answers

New Answer

+4

M Umer print displays the content to the console, return returns the value to a variable so you can use the value it just returned later in the program. in other words. print is just to print and return is to return a value.

+15

"return" returns a value to the main program when exiting a function. You can do further operations on the returned value. "print" only puts an output to the screen. You can't do anything with this afterwards than marveling its accomodating appearance. 😳

+8

here's a code example to Jan's explination: https://code.sololearn.com/cpGThocHw9cA/?ref=app

+8

return function returns their value to where they are called. for a function "foo" that returns 2 x = foo() now x has the value 2 returned by foo. Originally x has no value but just a space in memory, whenever such function is called it makes it so that the returned value was returned to the address of x. Function that doesnt have an explicit return keyword like the "print" function implicitly returns None. So if "foo" doesnt returned anything x = foo() x is None. __str__ and __repr__ of x also becomes None and printing this type of function appends None to any of the output

+7

each function is a return function. By default it returns None. If you want another value u need a return statement. Besides returning sth. functions can do other stuff: printing, saving files... whatever.

+2

Great explanation 🙌

+2

For example you can make a deal with return

+1

Thank You_ but what can we do else with return, for example..

+1

The return statement is NOT a function. It goes inside one at the end. As of Python 3, print IS a function. This question is harder to answer because the SoloLearn interpreter basically uses input() like function parameters for the whole program, and it uses print() like a return statement for the whole program. In normal Python (ie on a PC), these functions display text on a console as they are called, and the input() function waits for the user to enter something before continuing, which it then returns as a string. In short, return is a statement that goes inside functions when you want them to spit something out when they’re done. Print is just for showing some output to the user and cannot give output to the rest of the program. Print() and input() are the program to user communicator functions, return and “parameters” are the inner function program scope to outer program scope communicator… statement/format thigies.

-2

int k=10; k= k++; System.out.printl(k); Output in Java ??