args and kwargs in Python

Understanding *args and **kwargs in Python functions
python
Published

June 25, 2025

What are *args and **kwargs in Python?

I guess you have seen this syntax in Python functions, but you may not know what it means. Let’s taka a look at it!

def my_function(name, *args, **kwargs):
    print("args:", args)
    print("kwargs:", kwargs)    

    return

my_function('nima', 1, 2, 3, a=4, b=5)
args: (1, 2, 3)
kwargs: {'a': 4, 'b': 5}

As you can see, args is a variable of type tuple, and kwargs is a variable of type dict. Note that args can take any number of positional arguments, and kwargs can take any number of keyword arguments.

To read more, see: https://third-bit.com/sdxpy/oop/#oop-args