Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM
31-Aug-20251.
*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.