How to pass keyword parameters to a function in Python?

PythonServer Side ProgrammingProgramming

The double asterisk form of **kwargs is used to pass a keyworded, variable-length argument dictionary to a function. Again, the two asterisks (**) are the important and along with the word kwargs, indicate that there is a dictionary of variable-length keyworded arguments.

Like *args, **kwargs can take however many arguments you would like to supply to it. However, **kwargs differs from *args in that you will need to assign keywords.


def print_kwargs(**kwargs):
print_kwargs(kwargs_1="Whale", kwargs_2=5, kwargs_3= False, kwargs_4=2.1)


{'kwargs_4': 2.1, 'kwargs_1': 'Whale', 'kwargs_2': 5, 'kwargs_3': False}


Updated on 13-Feb-2020 06:20:41