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
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.
People also ask

Is *args a list or tuple in Python?
Python *args collects additional positional arguments into a tuple, which are accessible using tuple indexing and iteration.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ python โ€บ args-and-kwargs
Python *args and **kwargs (With Example)
How to pass **kwargs in Python?
We pass **kwargs in Python by placing double asterisks before a parameter. This way, we collect all keyword arguments as a dictionary inside the function.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ python โ€บ args-and-kwargs
Python *args and **kwargs (With Example)
Why do we use *args and **kwargs in Python?
In Python, *args and **kwargs enable functions to take a variable number of arguments. The former is used to pass a variable number of positional arguments to a function, whereas **kwargs allows us to pass a variable number of keyword arguments to a function.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ python โ€บ args-and-kwargs
Python *args and **kwargs (With Example)
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_function_arbitrary_keyword_arguments.asp
Python **kwargs
Arbitrary Kword Arguments are often shortened to **kwargs in Python documentations.
๐ŸŒ
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
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-main.html
Python main() - Command Line Arguments
$ python3 affirm.py -affirm Lisa Everything is coming up Lisa $ python3 affirm.py -affirm Bart Looking good Bart $ python3 affirm.py -affirm Maggie Today is the day for Maggie $ Command line arguments, or "args", are extra information typed on the line when a program is run.
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.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ types-of-arguments-in-python-1
Types of Arguments in Python - GeeksforGeeks
July 23, 2025 - Arguments are the values passed inside the parenthesis of the function. A function can have any number of arguments separated by a comma. There are many types of arguments in Python .
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Some way to get arguments of current function for passing along to another function even when not using *args/**kw - Python Help - Discussions on Python.org
June 10, 2024 - Often times I have a function that does not make use of *args/**kw for various reasons but still needs to pass along all arguments to another function. An example would be: def other_fun(a, b, c=7, d=9): ... def myfun(a, b, c=7, d=9): v = other_fun(a, b, c=c, d=d) # do some other post processing of v, often times depending on the input arguments ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Medium
medium.com โ€บ @staytechrich โ€บ python-intermediate-018-handling-variable-arguments-with-args-kwargs-and-command-line-1f74b9062895
Python Intermediate_018: Handling Variable Arguments with *args, **kwargs, and Command-Line Parsing with argparse | by CodeAddict | Medium
April 14, 2025 - In this post, we explore two essential Python features for handling variable arguments โ€” *args and **kwargs โ€” and the argparse module for creating command-line interfaces.
๐ŸŒ
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 basic understanding of the *args and **kwargs syntax in Python which allows you to pass a variable number of arguments to a function. *args is used for non-keyworded arguments and **kwargs is used for keyworded ...
๐ŸŒ
Aigents
aigents.co โ€บ learn โ€บ Arguments-Python
Arguments Python explained โ€“ short, clear and quickly!
๐Ÿ“š Read more at Towards Data Science ๐Ÿ”Ž Find similar documents ... In Python, you can use *args to pass any number of arguments to a function and **kwargs to pass any number of keyword arguments to a function.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-argparse
Master Python's argparse Module: Build Better CLIs | DataCamp
December 3, 2024 - The argparse module makes it easy to develop functional command-line interfaces. It automatically handles parameter parsing, displays helpful instructions, and provides errors when users provide incorrect information. In this tutorial, we'll look at how to use the Python argparse package.
๐ŸŒ
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.