What does **kwargs mean in Python?

Experience Level: Junior
Tags: Python

Answer

The double asterisk before a method or function parameter name means that multiple keyword arguments can be passed to the method/function.

Keyword argument is a key-value pair, the type of the **kwargs is dictionary.

Most frequently, name **kwargs is used, however, the name doesn't necessarily be only **kwargs, but it can be **anythingElse.

Example:

def sum(**kwargs)
    total = 0
    print(type(kwargs)) # Displays 
<class 'dict'>

    for value in kwargs.values():
        total += value


return sum(red=1, amber=2, green=3)

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself