0
Plz explain me the below code ...plz....especially line 2 .....
def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10))
4 Antworten
+ 2
def apply_twice (func,arg):
return func(arg)
def add_five(x):
return x+5
print (apply_twice(add_five,10))
here in the second line I have just replaced by func(arg)....plz reply fast....plz explain in easy words...
+ 1
Okay, think of it like this.
func = apply_twice()
arg = 10
^To better understand Line 2, just swap out func/arg with the above.
EXAMPLE:
return add_five(add_five(10))
^As you can see when you swap it out, you're calling the add_five function twice. The inner function argument is calling 'add_five' with the value of 10, and then the function returns the new value (10 + 5) of 15, which calls the function again with the new arg of 15. The function adds 5 again resulting in a value of 20.
0
Ever want to chat with someone on sololearn but don’t want to spam someone’s post or download discord? Try this: https://code.sololearn.com/c68t8ay789pm/?ref=app
0
func(func(arg))
but what does this actually mean or do...