+ 1
Can you have more than one argument with a default value?
If you do, how does the interpreter decide which parameter goes to which argument?
3 Respuestas
0
Your default value should be last when you define your function parameters. As long as the order is the same as the function call arguments it will work fine. You normally use positional arguments with multiple parameters. If you want to override the default parameter, you can use keyword arguments. It's just the name of the parameter put into the argument and set equal to a value.
0
Not an answer I'm afraid, but u second the question. For instance, if you had def function(a, b=1, c=2) and you passed f(4,5), would Python always assume that b was passed as 5 and c is default?
- 1
For a function to work without error, you need to pass exact number of arguments as the number of parameters used for function defination.
eg.
def add(a,b):
s=a+b
print s
add(5,10) # works without error
add(3) # Error