ID EN
Built-in Types

d[key]

Python 3.11

Return the item of d with key key. Raises a KeyError if key is not in the map.

Syntax

PYTHON
d[key]

Examples

Example 1
PYTHON
>>> class Counter(dict):
...     def __missing__(self, key):
...         return 0
>>> c = Counter()
>>> c['red']
0
>>> c['red'] += 1
>>> c['red']
1

See Also

KeyError KeyError collections.Counter collections.defaultdict