🐍 Python
Beginner
What is *args and **kwargs in Python?
Answer
*args allows a function to accept any number of positional arguments, collecting them into a tuple: def add(*args): return sum(args) — call as add(1, 2, 3, 4). **kwargs allows any number of keyword arguments, collecting them into a dict: def info(**kwargs): print(kwargs) — call as info(name="Alice", age=25). Both can be used together: def func(*args, **kwargs). Use * to unpack a sequence as positional arguments: func(*[1, 2, 3]). Use ** to unpack a dict as keyword arguments: func(**{"name": "Alice"}). These patterns are essential for writing flexible, forward-compatible APIs and when creating wrapper functions that pass arguments through to another function.