How to Pass a Single Dictionary Instead of Many Arguments into a Function in Python

on the usefulness of calling function(**arguments)

The aim of this page📝 is to learn from this encounter in code that goes something like

  • The called method initialize() is mapping the dictionary keys from the options variable to parameter names within its own function definition and thus accessing passed values
  • The coolness is that you can then extend the options dictionary without modifying the function call
  • As a side note, note the permissiveness of the initialize() function:
  1. none of the arguments are required as all have a default value set to None
  2. There also is **kwargs at the end of the function definition; i.e. you can pass a random number of dictionaries

LINKS

--

--

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com