Home / Python / Reference / Built-in functions

Python dict() function

Make a new dictionary.

Syntax

dict(**kwargs) / dict(pairs)

Build one from keyword arguments, or from a list of (key, value) pairs, often made with zip. Usually written directly with curly brackets.

Parameters

pairsan iterable of (key, value) pairs
**kwargskey=value arguments (keys become strings)

Return value

dict

Example

Code

print(dict(name="Sita", age=27))
print(dict([("a", 1), ("b", 2)]))
keys = ["x", "y"]
values = [10, 20]
print(dict(zip(keys, values)))

Output

{'name': 'Sita', 'age': 27}
{'a': 1, 'b': 2}
{'x': 10, 'y': 20}

Related

Learn it step by step in the free lesson Dictionaries & Sets, with exercises that check your answers.