📘 Lesson · Lesson 83
*args and **kwargs
Flexible Arguments
💡 At a Glance
*args lets a function take any number of positional arguments; **kwargs takes any number of keyword arguments.
*args (many values)
Python
def total(*args):
return sum(args)
print(total(1, 2, 3)) # 6
print(total(10, 20, 30, 40)) # 1006
100
**kwargs (named values)
Python
def show(**kwargs):
for key, value in kwargs.items():
print(key, "=", value)
show(name="Aman", marks=88)name = Aman
marks = 88
Summary
*argscollects extra positional args into a tuple.**kwargscollects extra keyword args into a dictionary.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.