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
| Name | Type | Description |
|---|---|---|
| mapping | mapping-like object | Alternative positional source with keys() and key lookup. |
| iterable | iterable of pairs | Alternative positional source; each entry must contain two items. |
| kwargs | keyword arguments | String-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))