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
Arbitrary Arguments are often shortened to *args in Python documentation.
๐ŸŒ
Python Tips
book.pythontips.com โ€บ en โ€บ latest โ€บ args_and_kwargs.html
1. *args and **kwargs โ€” Python Tips 0.1 documentation
I have come to see that most new python programmers have a hard time figuring out the *args and **kwargs magic variables. So what are they ? First of all, let me tell you that it is not necessary to write *args or **kwargs. Only the * (asterisk) is necessary.
๐ŸŒ
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.
Published ย  September 20, 2025
๐ŸŒ
Google
google.com โ€บ goto
5 Types of Python Function Arguments | Built In
Learn about the five different types of arguments used in python function definitions: default, keyword, positional, arbitrary positional and arbitrary keyword arguments.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ exceptions.html
Built-in Exceptions โ€” Python 3.14.3 documentation
Except where mentioned, they have an โ€œassociated valueโ€ indicating the detailed cause of the error. This may be a string or a tuple of several items of information (e.g., an error code and a string explaining the code). The associated value is usually passed as arguments to the exception classโ€™s constructor.
Find elsewhere
๐ŸŒ
Google
google.com โ€บ goto
Python Command-Line Arguments โ€“ Real Python
August 27, 2023 - Python command-line arguments directly inherit from the C programming language. As Guido Van Rossum wrote in An Introduction to Python for Unix/C Programmers in 1993, C had a strong influence on Python. Guido mentions the definitions of literals, identifiers, operators, and statements like break, continue, or return.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_function_arbitrary_keyword_arguments.asp
Python **kwargs
Arbitrary Kword Arguments are often shortened to **kwargs in Python documentations.
Top answer
1 of 11
1829

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
523

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.

๐ŸŒ
Nexacu
nexacu.com โ€บ home โ€บ insights-blog โ€บ python args
What are Python *args? | Nexacu
In the example below, a simple summary function has been defined. It will return the minimum, maximum and sum of any values passed to it. The use of *args means that it will work with any number of values provided. Learn more about Python, check out our Python Training Courses.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ argparse.html
argparse โ€” Parser for command-line options, arguments and subcommands
Simple class used by default by parse_args() to create an object holding attributes and return it. This class is deliberately simple, just an object subclass with a readable string representation.
๐ŸŒ
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 - Python functions accept positional arguments (matched by position) and keyword arguments (matched by name). Variable-length argument lists are handled by *args and **kwargs, which collect any extra positional or keyword arguments into a single parameter. You write a function that adds two numbers.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_command_line_arguments.htm
Python - Command-Line Arguments
Python Command Line Arguments provides a convenient way to accept some information at the command line while running the program. We usually pass these values along with the name of the Python script.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ function-argument
Python Function Arguments (With Examples)
Become a certified Python programmer. Try Programiz PRO! ... In computer programming, an argument is a value that is accepted by 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.
๐ŸŒ
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.
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-args
Python Args | Mastering Command-Line Arguments
February 7, 2024 - Python provides a built-in list named sys.argv for accessing command-line arguments. This list is automatically populated when you run a script, and it contains the command-line arguments that were passed to the script.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
How to acces *args - Python Help - Discussions on Python.org
December 4, 2024 - I have a function with a lot of parameters and sometimes one more all what I find on the net the parameters are interated in a loop, def create_combo(l_name, l_text, row,l_col, c_name, c_col, c_size, c_list, *args): l_name=ttk.Label(root,text=l_text) l_name.grid(row=row,column=l_col,padx=2,pady=2) c_name=ttk.Combobox(root,values=c_list, width=c_size) c_name.current(8) c_name.grid(row=row,column=c_col,padx=2,pady=2) sw_typ_list=("pushButton","revPushButton","nSwitch","uSwitch","eSwitch","...
๐ŸŒ
Medium
medium.datadriveninvestor.com โ€บ args-and-kwargs-in-python-the-flexible-functions-every-developer-must-master-71baf64ca63e
*args and **kwargs in Python โ€” The Flexible Functions Every Developer Must Master | by Anam Ahmed | Mar, 2026 | DataDrivenInvestor
4 days ago - This is one of the most common turning points in Python learning. At first, we define functions with fixed parameters. Clean. Predictable. Simple. But real-world programming? Itโ€™s messy, dynamic, and unpredictable. And thatโ€™s exactly where *args and **kwargs come in.
๐ŸŒ
Medium
medium.com โ€บ @rajshashwatcodes โ€บ args-and-kwargs-in-python-573f91508f33
*args and *kwargs in Python. Argument passing in python | by Shashwat Raj | Medium
January 27, 2023 - In Python, the *args syntax allows a function to accept an arbitrary number of arguments. The * operator is used to pass a variable number of arguments to a function.