def fun (arg,args=1,*arg,**keywords):
Python has a total of these four types of parameters, the first type of the most common, not to say, the second class, keyword parameters, Python can be found by the keyword parameters, the Python function of this feature makes the function parameters more flexible, not necessarily in order to pass, the third class: An asterisk is a non-keyword parameter collection, In the form of a tuple, the fourth class must provide the "pass parameter name = Pass argument value" as the pass parameter.
As for how to preach, I believe we all know that there is not much to say.
To illustrate, these four types of parameters are given precedence in python2, whether they are defining a function or passing a parameter, which is a sequential problem.
Here are the questions that are asked today:
1 defFun (*param,base=3):2result =03 foreachinchparam:4Result + = each5 6Result *=Base7 8 Print('result is', result)9 TenFun (5,1, 2, 3, 4,base=5)
Error:
def fun (*param,base=3):
^
Syntaxerror:invalid syntax
As I said above, this is obviously wrong, that is, the order is wrong. So is it OK to swap the Base,param? Obviously not, as explained above, the same precedence applies when passing parameters. So
Fun (base=5,5,1, 2, 3, 4,5) This is still not possible, because the order is wrong. This is a little awkward, if you want to juggle both, one solution is: Fun (5,5,1, 2, 3, 4,5)
Note: The problem in the above code seems to have been optimized in Python3, and there is no syntax error.
Python function positional parameters, keyword parameters, variable parameter precedence