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. Answer from scrdest on reddit.com
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_args_kwargs.asp
Python *args and **kwargs
Arbitrary Arguments are often shortened to *args in Python documentation.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ args-kwargs-python
*args and **kwargs in Python - GeeksforGeeks
Python provides two special symbols ... be passed to a function is not known in advance.* *args syntax allows a function to accept any number of positional arguments....
Published ย  June 11, 2026
๐ŸŒ
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.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ argparse.html
argparse โ€” Parser for command-line options, arguments and subcommands
The Python interpreter name followed by -m followed by the module or package name if the -m option was used. This default is almost always desirable because it will make the help messages match the string that was used to invoke the program on the command line. However, to change this default behavior, another value can be supplied using the prog= argument to ArgumentParser:
๐ŸŒ
Real Python
realpython.com โ€บ python-kwargs-and-args
Python args and kwargs: Demystified โ€“ Real Python
November 7, 2023 - In this step-by-step tutorial, you'll learn how to use args and kwargs in Python to add more flexibility to your functions. You'll also take a closer look at the single and double-asterisk unpacking operators, which you can use to unpack any iterable object in Python.
Top answer
1 of 11
1832

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.

๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ args-kwargs
Python *args and **kwargs: Syntax, Usage, and Examples
Start your coding journey with Python. Learn basics, data types, control flow, and more ... args collects extra positional arguments into a tuple, while *kwargs collects extra keyword arguments into a dictionary.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ command-line-arguments-in-python
Command Line Arguments in Python - GeeksforGeeks
In Python, command line arguments are values passed to a script when running it from the terminal or command prompt.
Published ย  December 17, 2025
Find elsewhere
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-use-args-and-kwargs-in-python-3
How To Use *args and **kwargs in Python 3 | DigitalOcean
March 6, 2026 - 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.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arguments.asp
Python Function Arguments
Python Examples Python Compiler ... Plan Python Interview Q&A Python Bootcamp Python Training ... Information can be passed into functions as arguments....
๐ŸŒ
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.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
*args and **kwargs in Python (Variable-Length Arguments) | note.nkmk.me
May 12, 2025 - In Python, you can define functions that accept a variable number of arguments by prefixing parameter names with * or ** in the function definition. By convention, *args (arguments) and **kwargs (keyw ...
๐ŸŒ
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.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ command-line-arguments-in-python
Command Line Arguments in Python (sys.argv, argparse) | Codecademy
Python Command line arguments are parameters passed to a script when itโ€™s executed from the command line interface. These arguments allow users to customize how a Python program runs without modifying the source code.
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ glossary โ€บ args
args (arguments) | Python Glossary โ€“ Real Python
A special syntax that allows a function to accept an undefined number of positional 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 ...
๐ŸŒ
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
๐ŸŒ
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 send a list of arguments with a variable size to a function. On Career Karma, learn how to use these argument keywords.
๐ŸŒ
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 .
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_function_arbitrary_arguments.asp
Python *args
Arbitrary Arguments are often shortened to *args in Python documentations.