The first is to specify the number of parameters to pass, there are two ways to transfer
One is the positional parameter, and the other is the keyword parameter
Passing parameters according to positional order
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" def Test (a B): #a和b为形参 Print (a) print (b) return 0test #1和2为实参
Run results
In order of position, 1 was assigned to the a,2 assignment to B.
Passing parameters according to the value of the formal parameter
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" def Test (a): print (a) print (b) return 0test (b=1,a=2)
Run results
The 1 is directly assigned to the parameter B, and the 2 is directly assigned to the parameter a
- Use both positional and keyword parameters
The positional parameter takes precedence over the keyword parameter when using the positional parameter and the keyword parameter to pass the parameter.
Positional parameters can only be preceded by the keyword parameter
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" def Test (a,b,c): print (a) print (b) print (c) return 0test (3,c=1,b=2)
Run results
Position parameter 3 to the parameter A, the keyword parameters C and b position order does not matter how much
Python function (ii)-parameter passing