Formal and actual parameters

1. Formal parameters and actual parameters

Formal parameter variable: The memory unit is allocated only when it is called. At the end of the call, the allocated memory unit is released. Therefore, the formal parameter is only valid within the function. After the function call ends and returns to the main calling function, it can no longer be used. formal parameter variables.

Actual parameters: can be constants, variables, expressions, etc. No matter what type of actual parameters are, they must have stable values ​​when calling a function. Therefore, methods such as assignment and input should be used to make the parameters stable. value.

例:def calc(x,y):

             res = x*y

             return res

       c= calc(a,b)

       print(c)

At this time, x and y are formal parameters, and a and b are actual parameters.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326168799&siteId=291194637