Interview Question

What are *args and **kwargs?

* collects positional arguments; ** collects keyword arguments.

💡 Concept ✅ Quick Revision 🐍 Python

Answer

*args and **kwargs are conventional parameter names for collecting extra arguments. • A starred parameter collects extra positional arguments into a tuple. • A double-starred parameter collects extra keyword arguments into a dictionary. • The names args and kwargs are conventions; the * and ** syntax defines the behavior.

💡 Simple Example

def show(*args, **kwargs): print(args) print(kwargs) show(1, 2, active=True)

Output

(1, 2) {'active': True}

⚡ Quick Revision

* collects positional arguments; ** collects keyword arguments.