Built-in Functions and Types

dict()

Build a mutable mapping from another mapping, two-item entries, keyword arguments, or a combination. Keys must be hashable. Later duplicate keys replace earlier values, including keyword overrides; replacing a value does not move its key. Iteration follows insertion order. Construction is shallow. Malformed entry lengths raise ValueError; invalid keys or non-iterable entries can raise TypeError.

Formal Syntax & Structure

python syntaxpython
dict(**kwargs)dict(mapping, /, **kwargs)dict(iterable, /, **kwargs)

Parameters & Attributes

NameTypeDescription
mappingmapping-like objectAlternative positional source with keys() and key lookup.
iterableiterable of pairsAlternative positional source; each entry must contain two items.
kwargskeyword argumentsString-keyed entries applied after the positional source.

Return Value

dict

A new mapping holding references to the supplied keys and values.

Working Example

Example Snippetpython
prices = dict([("pen", 2), ("book", 7)], pen=3)print(prices)print(list(prices))
Python Reference