Chapters
Python114 chapters

ReferenceBuilt-in functions

dict()

Builds a dictionary from keyword arguments or from pairs.

Signature

dict(**kwargs) or dict(pairs)

Parameters

NameMeans
pairsan iterable of two-item sequences

Returns

A new dict.

Example

Python
print(dict(a=1, b=2))
print(dict([("a", 1), ("b", 2)]))
print(dict(zip("ab", [1, 2])))

Output

{'a': 1, 'b': 2}
{'a': 1, 'b': 2}
{'a': 1, 'b': 2}

See also