The syntax is the * and **. The names *args and **kwargs are only by convention but there's no hard requirement to use them.

You would use *args when you're not sure how many arguments might be passed to your function, i.e. it allows you pass an arbitrary number of arguments to your function. For example:

>>> def print_everything(*args):
        for count, thing in enumerate(args):
...         print( '{0}. {1}'.format(count, thing))
...
>>> print_everything('apple', 'banana', 'cabbage')
0. apple
1. banana
2. cabbage

Similarly, **kwargs allows you to handle named arguments that you have not defined in advance:

>>> def table_things(**kwargs):
...     for name, value in kwargs.items():
...         print( '{0} = {1}'.format(name, value))
...
>>> table_things(apple = 'fruit', cabbage = 'vegetable')
cabbage = vegetable
apple = fruit

You can use these along with named arguments too. The explicit arguments get values first and then everything else is passed to *args and **kwargs. The named arguments come first in the list. For example:

def table_things(titlestring, **kwargs)

You can also use both in the same function definition but *args must occur before **kwargs.

You can also use the * and ** syntax when calling a function. For example:

>>> def print_three_things(a, b, c):
...     print( 'a = {0}, b = {1}, c = {2}'.format(a,b,c))
...
>>> mylist = ['aardvark', 'baboon', 'cat']
>>> print_three_things(*mylist)
a = aardvark, b = baboon, c = cat

As you can see in this case it takes the list (or tuple) of items and unpacks it. By this it matches them to the arguments in the function. Of course, you could have a * both in the function definition and in the function call.

Answer from David Webb on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_args_kwargs.asp
Python *args and **kwargs
By default, a function must be called with the correct number of arguments. However, sometimes you may not know how many arguments that will be passed into your function. *args and **kwargs allow functions to accept a unknown number of arguments.
🌐
GeeksforGeeks
geeksforgeeks.org › python › args-kwargs-python
*args and **kwargs in Python - GeeksforGeeks
... def multiply(*args): result = 1 for num in args: result *= num return result print(multiply(2, 3, 4)) ... The special syntax **kwargs allows us to pass any number of keyword arguments (arguments in the form key=value).
Published   September 20, 2025
Discussions

What are *args and **kwargs ?
Functions take arguments, sometimes you want to be able to pass a dynamic amount of arguments or different arguments - for example a function that adds all arguments passed to it - that's where *args and **kwargs come in. *args is used for passing positional arguments, **kwargs is used for passing keyword arguments. So, if you wanted to write the aforementioned function with *args you would write: def add(*args): return sum(args) #add(1,2,3,4) #10 or to better illustrate what's going on def read_args(*args): for arg in args: print(arg) #read_args(1,2,3,4) #1 #2 #3 #4 The same applies to **kwargs. The important thing to understand here is what's really going on under the hood: passing *args just creates a tuple from all of the positional arguments you pass it, once you understand that, manipulating the arguments is easy. So passing add(1,2,3,4) just means that you end up with a property args with the value of (1,2,3,4). And with kwargs it just converts all of the dynamic keyword arguments you've passed into a dictionary. Meaning passing read_kwargs(one=1, two=2) just leaves you with a property of type dictionary that equals {'one': 1, 'two': 2}. Also an important sidenote is that the keywords args and kwargs isn't important technically - you can name them anything you'd like, the only thing that python is concerned with is the *. Though always use the arg/kwarg as it's convention that's universal at this point. More on reddit.com
🌐 r/learnpython
18
127
November 18, 2017
What are args** and kwargs** and __somethinghere__ in python?
Some reading More on reddit.com
🌐 r/learnpython
18
67
October 15, 2024
Annotating args and kwargs in Python
You shouldn't use **kwargs in an API - APIs are boundaries, and boundaries should be as explicit as possible. You also shouldn't use *args, unless it's a simple varargs interface (like max(...)) or something with a clear definition (like str.format(...), and even then, I'm not completely on board). More on reddit.com
🌐 r/Python
33
105
January 9, 2024
What is the use of **kwargs?
Everything else mentioned here has been good, I’ll add an example where I have used it. I have a function that plots data. I take **kwargs after all my parameters. I don’t do anything with those parameters except pass them directly to the matplotlib plot call. Matplotlib has a bunch of optional keyword arguments that can be used to style the plot. So anyone using my code can either call it without any additional kwargs and get a default looking plot, or they can add kwargs and change the plot style entirely. More on reddit.com
🌐 r/learnpython
6
2
May 19, 2021
Top answer
1 of 11
1828

The syntax is the * and **. The names *args and **kwargs are only by convention but there's no hard requirement to use them.

You would use *args when you're not sure how many arguments might be passed to your function, i.e. it allows you pass an arbitrary number of arguments to your function. For example:

>>> def print_everything(*args):
        for count, thing in enumerate(args):
...         print( '{0}. {1}'.format(count, thing))
...
>>> print_everything('apple', 'banana', 'cabbage')
0. apple
1. banana
2. cabbage

Similarly, **kwargs allows you to handle named arguments that you have not defined in advance:

>>> def table_things(**kwargs):
...     for name, value in kwargs.items():
...         print( '{0} = {1}'.format(name, value))
...
>>> table_things(apple = 'fruit', cabbage = 'vegetable')
cabbage = vegetable
apple = fruit

You can use these along with named arguments too. The explicit arguments get values first and then everything else is passed to *args and **kwargs. The named arguments come first in the list. For example:

def table_things(titlestring, **kwargs)

You can also use both in the same function definition but *args must occur before **kwargs.

You can also use the * and ** syntax when calling a function. For example:

>>> def print_three_things(a, b, c):
...     print( 'a = {0}, b = {1}, c = {2}'.format(a,b,c))
...
>>> mylist = ['aardvark', 'baboon', 'cat']
>>> print_three_things(*mylist)
a = aardvark, b = baboon, c = cat

As you can see in this case it takes the list (or tuple) of items and unpacks it. By this it matches them to the arguments in the function. Of course, you could have a * both in the function definition and in the function call.

2 of 11
522

One place where the use of *args and **kwargs is quite useful is for subclassing.

class Foo(object):
    def __init__(self, value1, value2):
        # do something with the values
        print value1, value2

class MyFoo(Foo):
    def __init__(self, *args, **kwargs):
        # do something else, don't care about the args
        print 'myfoo'
        super(MyFoo, self).__init__(*args, **kwargs)

This way you can extend the behaviour of the Foo class, without having to know too much about Foo. This can be quite convenient if you are programming to an API which might change. MyFoo just passes all arguments to the Foo class.

🌐
Real Python
realpython.com › python-kwargs-and-args
Python args and kwargs: Demystified – Real Python
November 7, 2023 - In this case, since *args comes after **kwargs, the Python interpreter throws a SyntaxError. You are now able to use *args and **kwargs to define Python functions that take a varying number of input arguments.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-use-args-and-kwargs-in-python-3
How To Use *args and **kwargs in Python 3 | DigitalOcean
1 month ago - With *args, the function stays flexible. **kwargs collects extra keyword arguments into a single dict. Each argument must be passed with a keyword (e.g., name="Sam"). The double asterisk in **kwargs tells Python to pack all extra keyword arguments into a dict and bind it to the name kwargs.
🌐
Programiz
programiz.com › python-programming › args-and-kwargs
Python *args and **kwargs (With Examples)
Python passes variable length non keyword argument to function using *args but we cannot use this to pass keyword argument. For this problem Python has got a solution called **kwargs, it allows us to pass the variable length of keyword arguments to the function.
🌐
SaltyCrane
saltycrane.com › blog › 2008 › 01 › how-to-use-args-and-kwargs-in-python
How to use *args and **kwargs in Python - SaltyCrane Blog
January 3, 2008 - Or, How to use variable length argument lists in Python. The special syntax, *args and **kwargs in function definitions is used to pass a variable number of arguments to a function. The single asterisk form (*args) is used to pass a non-keyworded, variable-length argument list, and the double ...
Find elsewhere
🌐
Python Tips
book.pythontips.com › en › latest › args_and_kwargs.html
1. *args and **kwargs — Python Tips 0.1 documentation
*args and **kwargs are mostly used in function definitions. *args and **kwargs allow you to pass an unspecified number of arguments to a function, so when writing the function definition, you do not need to know how many arguments will be passed to your function.
🌐
Reddit
reddit.com › r/learnpython › what are *args and **kwargs ?
r/learnpython on Reddit: What are *args and **kwargs ?
November 18, 2017 -

I read few explaination but I just understood they are for variable arguments other than this I am confused

Top answer
1 of 5
85
Functions take arguments, sometimes you want to be able to pass a dynamic amount of arguments or different arguments - for example a function that adds all arguments passed to it - that's where *args and **kwargs come in. *args is used for passing positional arguments, **kwargs is used for passing keyword arguments. So, if you wanted to write the aforementioned function with *args you would write: def add(*args): return sum(args) #add(1,2,3,4) #10 or to better illustrate what's going on def read_args(*args): for arg in args: print(arg) #read_args(1,2,3,4) #1 #2 #3 #4 The same applies to **kwargs. The important thing to understand here is what's really going on under the hood: passing *args just creates a tuple from all of the positional arguments you pass it, once you understand that, manipulating the arguments is easy. So passing add(1,2,3,4) just means that you end up with a property args with the value of (1,2,3,4). And with kwargs it just converts all of the dynamic keyword arguments you've passed into a dictionary. Meaning passing read_kwargs(one=1, two=2) just leaves you with a property of type dictionary that equals {'one': 1, 'two': 2}. Also an important sidenote is that the keywords args and kwargs isn't important technically - you can name them anything you'd like, the only thing that python is concerned with is the *. Though always use the arg/kwarg as it's convention that's universal at this point.
2 of 5
32
It looks like http://book.pythontips.com/en/latest/args_and_kwargs.html explains it pretty well to me.
🌐
Reddit
reddit.com › r/learnpython › what are args** and kwargs** and __somethinghere__ in python?
r/learnpython on Reddit: What are args** and kwargs** and __somethinghere__ in python?
October 15, 2024 -

Hello everyone, I hope you all are doing well. I’m confused about these keywords in Python and what they do and where I can use them, since am new to python.

Anyone?

Top answer
1 of 10
75
Some reading
2 of 10
43
Symmetrically double-underscored names ('dunders') like __this__ aren't anything special in and of themselves. This is just a convention used by Python devs to mark things that are 'magic' in some way (usually, other builtin Python things rely on them in some way, e.g. __init__() is called when constructing a class, or __repr__() is called when printing). args and kwargs aren't special either; it's the asterisks (*foo and **bar) that are the magic bits. They are related and are used to make working with call signatures nicer, for either positional or keyword arguments, respectively. Sometimes you're not sure how many parameters a function will need to receive - sometimes it's one, sometimes it's twenty. For example, a function like sum() - you could lock it to only ever adding two numbers, sum(a, b), but that's not super nice for the users - we'd likely prefer to add ALL the numbers someone puts in, right? In more oldschool languages, a canonical solution would be to take some kind of a list of numbers, e.g. sum(numbers), and that works - but now your users have to slap extra braces around things, e.g. sum([1, 2, 3, 4]), which is annoying. Instead, the single-star syntax before an argument in a function signature (in our case, changing sum(numbers) => sum(*numbers)) flags to Python to wrap any positional arguments (that don't look like they belong to an earlier, non-starry arg) into a tuple under the hood. When passing inputs into a function, this is reversed - if you have anything listey and the function expects a bunch of positional arguments (starry or not, doesn't matter), if you put in an asterisk before the list, Python will unpack that into individual positional arguments. Double-star for kwargs does the same, except for named arguments - it implicitly wraps/unwraps dictionaries-and-friends like one-star wraps/unwraps tuples-and-friends.
🌐
freeCodeCamp
freecodecamp.org › news › args-and-kwargs-in-python
How to Use *args and **kwargs in Python
March 23, 2022 - `kwargs** allows us to pass a variable number of keyword arguments to a Python function. In the function, we use the double-asterisk (**`) before the parameter name to denote this type of argument. def total_fruits(**kwargs): print(kwargs, ...
🌐
W3Resource
w3resource.com › python-interview › what-is-the-purpose-of-the-args-and-kwargs-syntax-in-function-definitions.php
Understanding *args and **kwargs in Python Functions
The '*args` and '**kwargs' syntax in function definitions allows Python functions to accept a variable number of arguments. These special syntaxes provide flexibility when you don't know how many arguments will be passed to the function.
🌐
Scaler
scaler.com › home › topics › python › *args and **kwargs in python
*args and **kwargs in Python - Scaler Topics
November 16, 2023 - *args enable us to pass the variable ... that they contain a key-value pair, like a Python dictionary. **kwargs allows us to pass any number of keyword arguments....
🌐
Will Vincent
wsvincent.com › python-args-kwargs
Python *args and **kwargs | Will Vincent
September 20, 2018 - *args is used to pass a non-keyworded variable-length argument list to your function. **kwargs lets you pass a keyworded variable-length of arguments to your function. In a traditional Python function, you must explicitly define the number of ...
🌐
Medium
ravi-chan.medium.com › pythons-secret-weapon-how-to-use-args-and-kwargs-b320478102d1
Python’s Secret Weapon: How to Use *args and **kwargs | by Ravi Chandra | Medium
December 25, 2022 - Hope this article provide you the ... pass a variable number of arguments to a function. *args is used for non-keyworded arguments and **kwargs is used for keyworded arguments. These can be used together in a function definition ...
🌐
Career Karma
careerkarma.com › blog › python › python args and kwargs: a guide
Python args and kwargs: A Guide | Career Karma
December 1, 2023 - The *args and **kwargs keywords allow you to pass a variable number of arguments to a Python function. The *args keyword sends a list of values to a function. **kwargs sends a dictionary with values associated with keywords to a function.
🌐
WsCube Tech
wscubetech.com › resources › python › args-and-kwargs
Python *args and **kwargs (With Example)
November 5, 2025 - Learn about Python *args and **kwargs with examples. Understand how to use these flexible arguments to write more dynamic and reusable functions.
🌐
Note.nkmk.me
note.nkmk.me › home › python
*args and **kwargs in Python (Variable-Length Arguments) | note.nkmk.me
May 12, 2025 - By convention, *args (arguments) and **kwargs (keyword arguments) are commonly used as parameter names, but you can use any name as long as it is prefixed with * or **. The sample code in this article uses *args and **kwargs.
🌐
Analytics Vidhya
analyticsvidhya.com › home › args and kwargs in python in 2 minutes for data science beginner
Args and Kwargs in python in 2 minutes For Data Science Beginner
October 17, 2024 - Let’s try an example. ... **kwargs stands for keyword arguments to a Function. The only difference from args is that it uses keywords and returns the values in the form of a dictionary.
🌐
W3Schools
w3schools.com › python › gloss_python_function_arbitrary_keyword_arguments.asp
Python **kwargs
Python Functions Tutorial Function Call a Function Function Arguments *args Keyword Arguments Default Parameter Value Passing a List as an Argument Function Return Value The pass Statement i Functions Function Recursion ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial