What Do *args and **kwargs Mean in Python?

*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. Learn how and when to use each.

Published September 17, 2026

*args and **kwargs let a Python function accept an arbitrary number of arguments. *args collects any extra positional arguments into a tuple; **kwargs collects any extra keyword arguments into a dictionary. The names 'args' and 'kwargs' are just convention — the * and ** are what matter.

Common causes

  • Sometimes a function's exact set of arguments isn't known in advance, such as a wrapper that forwards arguments to another function
  • Decorators commonly need *args/**kwargs so they can wrap functions with any signature

How to fix it

  • Use *args when a function should accept any number of positional values, like a custom sum(*numbers) function
  • Use **kwargs when a function should accept arbitrary named options, like configuration parameters
  • Combine both — def f(a, b, *args, **kwargs) — to accept required arguments plus any extra positional and keyword arguments

Example

def greet(*args, **kwargs):
    print(args)    # ('hi', 'there')
    print(kwargs)  # {'loud': True}

greet('hi', 'there', loud=True)

FAQ

Can I use different names instead of args and kwargs?

Yes — *values or **options work identically. Only the * and ** prefixes are syntactically required; the names are just a strong convention.

More Python articles