args, **kwargs & Unpacking in Python

From the Python cheat sheet · Functions · verified Jul 2026

*args, **kwargs & Unpacking

Accept variable arguments and unpack iterables into function calls.

python
# *args — variable positional arguments
def total(*nums):
    return sum(nums)

total(1, 2, 3)  # 6

# **kwargs — variable keyword arguments
def config(**options):
    for k, v in options.items():
        print(f"{k}: {v}")

config(host="localhost", port=5432)
💡 *args becomes a tuple, **kwargs becomes a dict inside the function
⚡ Use *list and **dict to unpack when calling functions
📌 Parameter order: positional, *args, keyword defaults, **kwargs
🟢 The *args/**kwargs pattern is essential for decorators and wrapper functions
argskwargsunpacking

More Python tasks

Back to the full Python cheat sheet