What are *args and **kwargs in Python?
Quick answer
*args collects extra positional arguments into a tuple and **kwargs collects extra keyword arguments into a dictionary, which lets a function accept a variable number of arguments.
The names args and kwargs are conventions; the stars are what matter. They are useful for wrappers and decorators that must pass any arguments through to another function, and for APIs that accept optional settings.
The same stars work at the call site to unpack: print(*numbers) spreads a list into separate arguments and func(**options) spreads a dictionary into keyword arguments. The order in a signature is: normal parameters, *args, keyword-only parameters, **kwargs.
def report(title, *args, **kwargs):
print(title, args, kwargs)
report("Sales", 1, 2, region="EU", year=2026)
# Sales (1, 2) {'region': 'EU', 'year': 2026}
nums = [3, 4]
opts = {"sep": "-"}
print(*nums, **opts) # 3-4