2 odpowiedzi
+ 2
no such thing as a stupid question. Return is what you get back from a function. for instance if I had a simple function to add 2 numbers, I could return the result.
def add(x,y):
c=x+y
return c
If I called this function with add(2,3) it would return c which is 2+3 .. So it would return 5.
so if I said
number=add(2,3)
The variable number is assigned 5 because that's what was returned to it
functions don't have to return anything.
def add(x,y):
c=x+y
if I call this with add(2,3) it would take the 2 and 3, add them together to assign the value to c.. But it wouldn't do anything with this information.
number=add(2,3) in this scenario doesn't return a value to number
+ 2
In one sentence, return defines the value which is given back from a function.
When you define in Python your own functions, you have the possibility to define a return value. This concept is similar to mathematical functions like sin (x), exp (x) etc.
You can assign a function like these ones to a variable. The value of the variable is the return value from the function.
For example:
y = sin (x)