conversion

dict()

Constructs a dictionary from keyword args, another mapping, or an iterable of key/value pairs. Insertion order is preserved (Python 3.7+).

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

Parameters

Parameter Purpose
mapping Existing dict-like to copy
iterable Iterable of (key, value) pairs
**kwargs Keyword args become string keys

Examples

dict(a=1, b=2)

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

dict([('x', 1), ('y', 2)])

Returns {'x': 1, 'y': 2}

dict(zip(['a', 'b'], [1, 2]))

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

Gotcha

Keyword-arg form only allows valid identifier keys. Later keys silently override earlier ones — no duplicate warning.

Related built-ins

← All Python built-ins