+ 1
python func
alright, i can't get my head around it can someone explain the use of the first def and the "arg" in detail.... def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10))
6 Réponses
+ 7
Even if you use another name instead of arg and func, it will work as same.
def is used to define function.
First in the line,
print(apply_twice(add_five,10))
You are calling the apply_twice function where you are giving add_five function passed inside the first parameter and the 10 in the second parameter.
Next in the apply_twice function, you are returning func(func(arg)) here the func is refered to the add_five and arg is refered to 10.
So in short, you are returning
return add_five(add_five(10))
Here .First add_five(10) will return 10+5 which is 15.Now if you simplify the previous line, it becomes:
return add_five(15)
now it returns 15+5=20
So it returns 20 and prints 20
Summery,
return func(func(arg))
=>return add_five(add_five(10))
=>return add_five(15)
=>return 20
So it prints 20.
+ 4
Tomoe
Explanation is here. In your case output is 20 because of 2 arguments in function.
https://code.sololearn.com/cgfonDJu8pH0/?ref=app
0
def is a pre defined and we using it which declearing or defining function in python arg is a argument which u passing in rough way u can say it a passing function variable u van give any any name instead of args but u cannot change def with any bame gere u defined two functions first one is apply_twice and second one is afd_five(x) in both function u passing one parameter in print statement u calling add five function and passing value 10 so 10 will pass to x and return statement will execute and it will return 10+5 which is 15
same will be apply for next function becz in print statement u calling two functions so first time add will call then
0
Akshat WhiteHat Junior is a scam business!
0
Can you help me ...i dont know how to write pythone code to count aspecfic name in text in file and how much time it is take to finish