Reputation: 13025
Suppose there is a function defined as
def function1(x, y, z=True,a):
...
...
When I call function1, it seems I can call the function in the following manners
function1(10,2,3)
function1(x=10,y=2,a=3)
But calling function1(x=10,y=2, 3)
will cause error, where 3
should be assigned to a
. Generally, what are the correct ways to call a function withou causing potential issues.
Upvotes: 0
Views: 786
Reputation: 5115
That is not a valid way to define a function in python 2 or 3. Default arguments (ones with default values, namely x=y
) must come after non-default arguments. With your function definition, you should receive the following error:
File "<stdin>", line 1
SyntaxError: non-default argument follows default argument
Upvotes: 3