code show as below:
# -*- coding:gb2312 -*-
def test(a,b,funC):
result = funC(a,b)
return result
funC = eval(input("请输入函数"))
num = test(11,22,funC)
print(num)
Execute as follows:
I input:
lambda x,y:x y
or
lambda x,y:x**y
, both will be successful.
My question is:
The letters after lambda are x and y, which are different from a and b in the previous funC(a,b)
Why can it also be true?
In other words, why shouldn't it be lambda a,b:a b? Shouldn't the letters I enter be the same as the letters above?
a and b
in
lambda a,b:a+bare formal parameters and are used as local variables in the function body, while
x and yare used as local variables in the function body.
variables can be real Parameter . So it is used as the actual parameter of lambdafunction expression. It does not need to be the same.