Python newbie asks questions about formal parameters and actual parameters
phpcn_u1582
phpcn_u1582 2017-06-13 09:24:44
0
1
1064

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?

phpcn_u1582
phpcn_u1582

reply all(1)
扔个三星炸死你

Actual parameter (argument): The full name is "actual parameter" which is the parameter passed to the function when is called. Actual parameters can be constants, variables, expressions, functions , etc.
Formal parameter (parameter): Full name It is a "formal parameter" because it is not an actual variable, so it is also called a dummy variable. It is the parameter used when defining the function name and function body.

So

a and b in lambda a,b:a+b are formal parameters and are used as local variables in the function body, while x and y are used as local variables in the function body. variables can be real Parameter . So it is used as the actual parameter of lambda function expression. It does not need to be the same.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template