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

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any Python Language Question?