Store values under keys and read them by key. Keys keep insertion order; writing an existing key replaces its value without moving the key. Each key has one value.
Create an empty dictionary or copy another dictionary or a source of (key, value) pairs. Named arguments add entries afterward and replace matching keys. Nested values are shared with the source.
Create a dictionary by writing key: value pairs between braces. Repeated keys keep the last value.
Syntax
{"mode": "farm", "retries": 3}
Parameters
Name
Description
keyAny
Key identifying the value. Numbers, strings and tuples of valid keys are allowed; lists, dictionaries and sets are not. True, 1 and 1.0 identify the same key.
Required · Positional or named
No default
valueAny?
Value stored for that key.
Required · Positional or named
No default
Returns
dict — A new dictionary that preserves the literal entry order.
Build a dictionary from key: value pairs calculated while looping through a source. Repeated keys replace earlier values. Use if to filter items; multiple for/if clauses are allowed. Loop variables stay inside this expression.
Return a live view of (key, value) tuples in insertion order. It reflects later dictionary changes. Loop over it or convert with list() to use indexes.
Syntax
dictionary.items()
Returns
dict_items — A dict_items view; it cannot be indexed directly.
Return a new dictionary with the same entries. Adding, removing or replacing entries does not change the original; nested collections are still shared.
Syntax
dictionary.copy()
Returns
dict — A new dict; nested collections are not copied.
Add entries to this dictionary from another dictionary or a source of (key, value) pairs, then apply named arguments. Matching keys are replaced without changing their position.