dict(**kwargs)
dict(mapping, **kwargs)
dict(iterable, **kwargs)

The dict() function creates a dictionary in Python.

Parameters

A keyword argument is an argument preceded by an identifier (e.g., name=). Use kwarg=value to pass keyword arguments to the dict() constructor to create dictionaries.

Return Value

dict() returns an empty dictionary.

Examples

If no arguments are passed, an empty dictionary is created:

dict()  # {}

If a mapping object is passed, which implements the keys and __getitem__ methods, its keys and values become the keys and values of the dictionary. If an iterable sequence is passed, each element must contain two elements. The first becomes the key, and the second becomes the value.

dict([(1, 2), (3, 4)])  # {1: 2, 3: 4}

If key-value arguments kwargs are passed, their names become the keys of the dictionary, and the values become the values.

dict(first=1, second=2)  # {'first': 1, 'second': 2}