Is it possible to define a function argument's default value to another argument in the same function definition? Something like:
def func(a, b=a):
print a, b
but that didn't work.
Is it possible to define a function argument's default value to another argument in the same function definition? Something like:
def func(a, b=a):
print a, b
but that didn't work.
No. This is not possible. The Python interpreter thinks that you want to assign the default value of argument
b
to a global variablea
when there isn't a global variablea
.You might want to try something like this: