What are Python’s *args and **kwargs?
Ask by ICSM Computer
Updated 31 Aug 2025
1.
*args(Non-keyword arguments)This is used to pass a variable number of accepted arguments to a function. Inside the function,
argsis treated as a tuple.Example:
Here,
*argslets the function many number of positional values as arguments.2.
**kwargs(Keyword arguments)This is used to pass a variable number of keyword arguments (key=value) pair to a function. Inside the function,
kwargsis treated as a dictionary.Example:
Output:
3. Using
*argsand**kwargstogetherThis can use both in the same function, but
*argsmust come before**kwargs.Example:
Output:
4. Argument unpacking
This can also use
*and**when calling functions to unpack values.Example:
In short:
*args→ collects extra positional arguments into a tuple.**kwargs→ collects extra keyword arguments into a dictionary.