Arushi
asked

Expert
Abhay Jajodia answered
Hello Arushi, really nice question.
Both *args and **kwargs let a function take a flexible number of arguments, but they work in different ways.
*args collects positional arguments. These are the values you pass without naming them:
def demo(*args):
print(args)
demo(1, 2, 3)
# (1, 2, 3)
So args turns into a tuple of whatever positional values you give.
**kwargs collects keyword arguments — the ones you pass using names:
def demo(**kwargs):
print(kwargs)
demo(name="Arushi", age=20)
# {'name': 'Arushi', 'age': 20}
This becomes a dictionary where the keys are the argument names.
The simple way to remember it:
*args→ any number of unnamed values**kwargs→ any number of named values
They’re both handy when you don’t know ahead of time how many arguments someone will pass into your function.
If you have further questions, I'm here to help.
Python
This question was asked as part of the Learn Python Intermediate course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer