+ 1
Can you explain better what is return function?
def apply_twice(func,arg): return func(func(arg))def add_twice (x): return x+5print (apply_twice(add_five,10))the result is 20how did this happen? can you help me?
4 Answers
+ 3
By default, a function, when run will return or end with None. So if you want to get something back from a function you can use the keyword return to give back something when the function is run.
In your example, there is a missing function "add_five" but I assume what you are doing is passing a function and arguement through a function that then takes that arguement and runs is through the passed function.
+ 1
If a function gets to a return statement (there can be more than one in a function) it will end there and spit out the return. So you can do things like
if this:
return this
else:
return that
There would be two potential returns but only one will get returned.
+ 1
return is the keyword for outputing a results from inside of a funtion.
0
Can you explain, when i type return, it returns before the last function?