Can you explain better what is return function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

19th Jul 2016, 5:05 AM
Jeryl Toquero
Jeryl Toquero - avatar
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.
19th Jul 2016, 6:10 AM
jj Fer
jj Fer - avatar
+ 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.
19th Jul 2016, 3:44 PM
jj Fer
jj Fer - avatar
+ 1
return is the keyword for outputing a results from inside of a funtion.
2nd Aug 2016, 9:54 PM
MICHAŁ FRĄCKOWIAK
MICHAŁ FRĄCKOWIAK - avatar
0
Can you explain, when i type return, it returns before the last function?
19th Jul 2016, 8:45 AM
Andreas Kilian
Andreas Kilian - avatar