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
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί args-kwargs-python
*args and **kwargs in Python - GeeksforGeeks
In Python, *args and **kwargs are used to allow functions to accept an arbitrary number of arguments. These features provide great flexibility when designing functions that need to handle a varying number of inputs.
Published Β  September 20, 2025
🌐
W3Schools
w3schools.com β€Ί python β€Ί python_args_kwargs.asp
Python *args and **kwargs
Arbitrary Keyword Arguments are often shortened to **kwargs in Python documentation.
Discussions

python - Use of *args and **kwargs - Stack Overflow
It appears impossible to expand ... The expanded list may only be followed by keyword arguments I believe. Is there a way to get around that? 2014-09-25T15:59:24.32Z+00:00 ... @mlh3789 yes, and this works with python3, only.... More on stackoverflow.com
🌐 stackoverflow.com
python - Normal arguments vs. keyword arguments - Stack Overflow
How are "keyword arguments" different from regular arguments? Can't all arguments be passed as name=value instead of using positional syntax? ... You might also want to read PEP 3102 -- they're tidying up some of this stuff in Python 3. See: python.org/dev/peps/pep-3102 ... And whether or not there is a default value has nothing to do with ... More on stackoverflow.com
🌐 stackoverflow.com
python function *args and **kwargs with other specified keyword arguments - Stack Overflow
I have a Python class with a method which should accept arguments and keyword arguments this way class plot: def __init__(self, x, y): self.x = x self.y = y def set_axis(s... More on stackoverflow.com
🌐 stackoverflow.com
September 18, 2025
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
🌐
Real Python
realpython.com β€Ί python-kwargs-and-args
Python args and kwargs: Demystified – Real Python
November 7, 2023 - Okay, now you’ve understood what *args is for, but what about **kwargs? **kwargs works just like *args, but instead of accepting positional arguments it accepts keyword (or named) arguments.
🌐
W3Schools
w3schools.com β€Ί python β€Ί gloss_python_function_keyword_arguments.asp
Python Keyword Arguments
Python Overview Python Built-in ... Q&A Python Bootcamp Python Certificate Python Training ... You can also send arguments with the key = value syntax....
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.

🌐
DigitalOcean
digitalocean.com β€Ί community β€Ί tutorials β€Ί how-to-use-args-and-kwargs-in-python-3
How To Use *args and **kwargs in Python 3 | DigitalOcean
3 weeks ago - 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. Keys are the parameter names used at the call site; values are the corresponding values.
🌐
Python
peps.python.org β€Ί pep-3102
PEP 3102 – Keyword-Only Arguments | peps.python.org
In particular, it enables the declaration of β€œkeyword-only” arguments: arguments that can only be supplied by keyword and which will never be automatically filled in by a positional argument.
Find elsewhere
🌐
Trey Hunner
treyhunner.com β€Ί 2018 β€Ί 04 β€Ί keyword-arguments-in-python
Keyword (Named) Arguments in Python: How to Use Them
When we use keyword/named arguments, it’s the name that matters, not the position: So unlike many other programming languages, Python knows the names of the arguments our function accepts. If we ask for help on our function Python will tell us our three arguments by name: Note that functions can be called with ...
🌐
Educative
educative.io β€Ί blog β€Ί what-are-keyword-arguments-in-python
What are keyword arguments in Python?
August 18, 2025 - Keyword arguments are passed with the syntax name=value, and non-keyword arguments are passed positionally (by order). Positional arguments: Passed in the order the parameters are defined.
Top answer
1 of 10
417

There are two related concepts, both called "keyword arguments".

On the calling side, which is what other commenters have mentioned, you have the ability to specify some function arguments by name. You have to mention them after all of the arguments without names (positional arguments), and there must be default values for any parameters which were not mentioned at all.

The other concept is on the function definition side: you can define a function that takes parameters by name -- and you don't even have to specify what those names are. These are pure keyword arguments, and can't be passed positionally. The syntax is

def my_function(arg1, arg2, **kwargs)

Any keyword arguments you pass into this function will be placed into a dictionary named kwargs. You can examine the keys of this dictionary at run-time, like this:

def my_function(**kwargs):
    print str(kwargs)

my_function(a=12, b="abc")

{'a': 12, 'b': 'abc'}
2 of 10
224

There is one last language feature where the distinction is important. Consider the following function:

def foo(*positional, **keywords):
    print "Positional:", positional
    print "Keywords:", keywords

The *positional argument will store all of the positional arguments passed to foo(), with no limit to how many you can provide.

>>> foo('one', 'two', 'three')
Positional: ('one', 'two', 'three')
Keywords: {}

The **keywords argument will store any keyword arguments:

>>> foo(a='one', b='two', c='three')
Positional: ()
Keywords: {'a': 'one', 'c': 'three', 'b': 'two'}

And of course, you can use both at the same time:

>>> foo('one','two',c='three',d='four')
Positional: ('one', 'two')
Keywords: {'c': 'three', 'd': 'four'}

These features are rarely used, but occasionally they are very useful, and it's important to know which arguments are positional or keywords.

🌐
Pybites
pybit.es β€Ί articles β€Ί the-arbitrary-keyword-arguments-args-and-kwargs-dont-come-for-free-in-python
The Arbitrary (Keyword) Arguments (args And Kwargs) Don't Come "for Free" In Python - Pybites
August 10, 2023 - Python allows you to use *args and **kwargs in function definitions to accept an arbitrary number of positional and keyword arguments, respectively. ... In the above example, the arbitrary_args function is defined to accept any number of positional ...
🌐
Python
docs.python.org β€Ί 3 β€Ί glossary.html
Glossary β€” Python 3.14.3 documentation
Also see Annotations Best Practices for best practices on working with annotations. ... A value passed to a function (or method) when calling the function. There are two kinds of argument: keyword argument: an argument preceded by an identifier (e.g.
🌐
Python Tips
book.pythontips.com β€Ί en β€Ί latest β€Ί args_and_kwargs.html
1. *args and **kwargs β€” Python Tips 0.1 documentation
first normal arg: yasoob another arg through *argv: python another arg through *argv: eggs another arg through *argv: test Β· I hope this cleared away any confusion that you had. So now let’s talk about **kwargs Β· **kwargs allows you to pass keyworded variable length of arguments to a function. ...
🌐
Towards Data Science
towardsdatascience.com β€Ί home β€Ί latest β€Ί 10 examples to master *args and **kwargs in python
10 Examples to Master *args and **kwargs in Python | Towards Data Science
January 20, 2025 - *kwargs does the same as args but for keyword arguments. They are stored in a dictionary because keyword arguments are stored as name-value pairs. Python does not allow positional arguments to follow keyword arguments.
🌐
Python
peps.python.org β€Ί pep-0736
PEP 736 – Shorthand syntax for keyword arguments at invocation | peps.python.org
January 3, 2008 - This redundancy discourages use of named arguments and reduces readability by increasing visual noise. There are two ways to invoke a function with arguments: by position and by keyword.
🌐
Tutorialspoint
tutorialspoint.com β€Ί python β€Ί python_keyword_arguments.htm
Python - Keyword Arguments
Python allows to pass function arguments in the form of keywords which are also called named arguments. Variables in the function definition are used as keywords. When the function is called, you can explicitly mention the name and its value.
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί argparse.html
argparse β€” Parser for command-line options, arguments and subcommands
Generally, argument defaults are specified either by passing a default to add_argument() or by calling the set_defaults() methods with a specific set of name-value pairs. Sometimes however, it may be useful to specify a single parser-wide default for arguments. This can be accomplished by passing the argument_default= keyword argument to ArgumentParser.
🌐
Real Python
realpython.com β€Ί ref β€Ί glossary β€Ί kwargs
kwargs (keyword arguments) | Python Glossary – Real Python
In Python, **kwargs is a special syntax for defining functions that accept an undetermined number of keyword arguments.
🌐
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.