0
Guys please help me
I didn't understand the return function can any one help me
6 Antworten
+ 4
The return means that function will give you "something" to you, and you can use a variable to store it. By the way, if you don't return anything, the default return will be None.
For example,
def add(num1, num2):
return num1 + num2
added_num = add(10, 20) # added_num = 30
Hope this would help.
+ 2
The "return" is a keyword in a programming language. What the "return" keyword concatenating is the variable(or you can think as a value).
+ 1
Aaron Yang so its just like a variable?
+ 1
Return gives you back what you write after it. So once you call a certain function if you assign the function to a variable what Is in the return Will become a variable (names can be arbitraly) else if you write print function () the return value Will be Just printed
+ 1
return function is used when you define a function, and want to end that function, it returns whatever value you want to return to the computer, so you can use it whenever it is needed later.
0
Lets start with concepts.
1. A function is something that does something, like an algorithm.
1. A keyword is a special case string that tells the compiler that something is going to happen. Like int is a keyword to tell the compiler to allocate memory for an integer, and store an int
So return is a keyword, which is placed at the end of the function to specify that this is what the function equals at the end. For example lets look at a basic add function in
int Add(int a, int b)
{
return a+b;
}
If i said that
int c = Add(1,2);
It would call the function and pass a as 1 and b as 2, and mathematically 1+2=3
so add now becomes the integer value 3. Return just means this is what i become.