Skip to content
Advertisement

Pass a dictionary as default arguments of a function

let’s say i have a function like this:

JavaScript

I want to pass a dict like this to the function as the only argument.

JavaScript

which should change the values of the a and c arguments but b still remains the default value.

since foo is in an external library i don’t want to change the function itself.

is there any way to achieve this?

EDIT

to clarify foo has both default arguments like a and has keyword arguments like **kwargs

when i do this:

JavaScript

**arg_dict is passed as the **kwargs and other arguments stay the default value.

Advertisement

Answer

You can unpack the arg_dict using ** operator.

JavaScript
Advertisement