In the second example you provide 3 arguments: filename, mode and a dictionary (kwargs
). But Python expects: 2 formal arguments plus keyword arguments.
By prefixing the dictionary by ‘**’ you unpack the dictionary kwargs
to keywords arguments.
A dictionary (type dict
) is a single variable containing key-value pairs.
“Keyword arguments” are key-value method-parameters.
Any dictionary can by unpacked to keyword arguments by prefixing it with **
during function call.