Use of double asterisk (**) in python

Gaurav Patil
Mar 4, 2022
Photo by James Harrison on Unsplash

Introduction :

Double asterisk (**) is used for packing/unpacking a dictionary.

Flexibility provided by ** is that we can unpack or pack dictionary of any number of key-value pair.

Unpacking dictionary :

Packing dictionary :

To sum up:

In unpacking a dictionary, we need a predefined dictionary which is used as an input in a function and we get all the items unpacked.

In packing a dictionary, we create a dictionary using arguments as keys and values of arguments as values for a newly created dictionary.

--

--

Gaurav Patil

Machine Learning Engineer drawing insights from mathematics.