# I still don't really get return. Can someone pls explain it to me properly?

3/5/2017 1:27:03 AM

Jethro Tan19 Answers

New AnswerFor a function to return something means it gives back a value you can use. Ex: If you have a function that multiplies 3 numbers together (let's say multiply()), you'll probably want that result back. So every time you use multiply(), it's like it's replaced it with whatever result you return. Ex: multiply(2, 4, 3) is the same as 24. You can print out that value immediately, store it in a variable, or use that value for another function.

For example if you have method which does addition of two numbwrs and you want to use that sum later i. e. public int sum() { int a, b, sum; sum = a + b; return sum; When you call the method sum() ; it will return value of sum and in next line you can write if(sum >5) { System.out.println("sum is greater) ; else{ System.out.println("sum is smaller) ; }

To understand return, see it as a memory holder for whatever is inputed so that it can be recalled several times in the code. It goes alongside the def function which specifies what the purpose of the code is while the expected sub values are the return function. The final output can then be called or printed. E.g Def color_mixer(red, blue, yellow, white, black) red + blue return purple red + yellow return orange blue + yellow return green red + white return pink black + white return gray red + blue + yellow return brown color_mixer(red, blue, yellow, white, black)

Another good way to think about it is to imagine a function as a black box. You put your arguments into it, turn it on, and something comes out the other side. The rest of the programme doesn't actually need to know what's going on inside the box. It just needs the finished product. 'Return' is the thing the box spits out.

Returning is optional because even you can use print function and call the values. But short ways is to write return and Then it will return the values or calculated one

For a function to return something means it gives back a value you can use. Ex: If you have a function that multiplies 3 numbers together (let's say multiply()), you'll probably want that result back. So every time you use multiply(), it's like it's replaced it with whatever result you return. Ex: multiply(2, 4, 3) is the same as 24. You can print out that value immediately, store it in a variable, or use that value for another function.

Return is also a function which returns the current running function results. i.e in the form of addition of two numbers or like other. return only returns the function results after the completion of the function.

He is when a creator of a variable, but with not a variable for pick, you can save in one using a function and print he, or print(function)

The main point of using return in a function is that let the function do it's operations on the given values and at the final it should store the result and return it to us.... And after return we will be able to use the stored result in different operations and different ways as we want.