I have a function that accepts *args, but I would like to set the default tuple if none are provided. (This is not possible with the help def f(*args=(1, 3, 5))that a calls SyntaxError.) What would be the best way to do this? The proposed functionality is shown below.
f()
f(1)
f(9, 3, 72)
The following function gwill provide the correct functionality, but I would prefer *args.
def g(args=(1, 2, 3)):
return "I received {}!".format(', '.join(str(arg) for arg in args))
g()
g((1,))
g((9, 3, 72))
source
share