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 collects extra positional arguments into a tuple and **kwargs collects extra keyword arguments into a dictionary. They let a function accept any number of inputs.
The concept
The names args and kwargs are convention; the real syntax is the star. One star packs positional values into a tuple, two stars pack name=value pairs into a dict.
The same stars work in the opposite direction at call time: f(*list) unpacks a list into arguments, f(**dict) unpacks a dict into keyword arguments.
What the function receives
Practical examples
Sum any number of values
def total(*nums):
return sum(nums)
total(1, 2, 3) # 6Flexible options
def connect(host, **opts):
timeout = opts.get('timeout', 30)
return host, timeoutUnpacking when calling
nums = [1, 2, 3]
print(*nums) # 1 2 3
config = {'sep': '-'}
print('a', 'b', **config) # a-bForwarding to another function (decorators)
def wrapper(*args, **kwargs):
return original(*args, **kwargs)Common mistakes
- Putting **kwargs before *args in the definition — order must be normal, *args, **kwargs.
- Expecting args to be a list; it is a tuple.
- Overusing them so callers cannot tell what the function accepts.
Key takeaways
- *args = tuple of positional extras, **kwargs = dict of keyword extras.
- Stars unpack at call time too.
- Use them for wrappers and flexible APIs, not everywhere.
FAQ
Do I have to call them args and kwargs?
No, only the * and ** matter, but those names are the convention.
Can I mix them with normal parameters?
Yes: def f(a, b, *args, key=1, **kwargs).