Python Language *args and **kwargs Using *args when writing functions


You can use the star * when writing a function to collect all positional (ie. unnamed) arguments in a tuple:

def print_args(farg, *args):
   print("formal arg: %s" % farg)
   for arg in args:
       print("another positional arg: %s" % arg)

Calling method:

print_args(1, "two", 3)

In that call, farg will be assigned as always, and the two others will be fed into the args tuple, in the order they were received.