I have been coming across function calls that use arguments that are not in the function definition. I would like to know how that works (i.e. how the compiler interprets this).

For example, this function call:

 interp.plot_confusion_matrix(figsize=(12,12), dpi=60)

uses the variables "figsize" and "dpi", but neither of them turn up in the definition of plot_confusion_matrix: help(interp.plot_confusion_matrix) gives:

plot_confusion_matrix(normalize: bool = False, title: str = 'Confusion matrix', 
cmap: Any = 'Blues', norm_dec: int = 2, slice_size: int = None, **kwargs) -> None 
method of fastai.vision.learner.ClassificationInterpretation instance
    Plot the confusion matrix, with `title` and using `cmap`.

Why is it not an error to use "figsize" and "dpi" in the function call if they are not arguments of the function? How does this work in python?


1 Answer 1


Those parameters are taken care of by **kwargs in the function definition. You can look how this is dealt with by the code in the fastai repo and looking for **kwargs in the function definition.
Some explanations about how this works can be found on SO: https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.