+ 1
*Args and default values
Is it possible to call a function that has a default value and an *args argument (not **kwargs), without setting the default value again? e.g. def my_func(a, b=10, *args): print(a, b, args) so b should be 10, and has not been defined when calling the function; or is there a way to define it so that you do not use the optional parameter?
2 Respuestas
+ 2
How about making 'b' a keyword argument:
def your_func(a, *args, b=10):
print(a, b, args)
Notice 'b' after '*args'
E.g.:
your_func(1) -> 1 10 ()
your_func(1, 2, 3, 4) -> 1 10 (2, 3, 4)
your_func(1, b=8) -> 1 8 ()
your_func(1, 2, 3, b=8) -> 1 8 (2, 3)
0
Ah. Thank you!