Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 926f851

Browse files
committed
Added brief mapping type description
1 parent 2c554e3 commit 926f851

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/basics/stdtypes.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,23 @@ another).
304304
Mapping type
305305
============
306306

307+
A mapping object maps hashable values to arbitrary objects. Mappings are
308+
mutable objects. There is currently ony one standard mapping type, the
309+
*dictionary*. In few words mappings are collections of keys and their values.
310+
311+
A dictionary's keys are almost arbitrary values. Values that are not hashable
312+
may not be used as keys. Values that compare equal (such as ``1``, ``1.0`` and
313+
``True``) can be used interchangeably to index the same dictionary entry.
314+
315+
Dictionaries can be created by several means:
316+
317+
- Use braces to denote the empty dictionary: ``{}``
318+
- Use a comma-separated list of ``key: value`` pairs with braces:
319+
``{'first_name': 'Serhii', 'last_name': 'Horodilov', 'age': 34}
320+
- Use a dict comprehension: `{x: x ** 2 for x in range(10)}``
321+
- Use the type constructor: ``dict()``, ``dict([('key', 100)])``,
322+
``dict(key=100)``
323+
307324
Value comparisons
308325
-----------------
309326

0 commit comments

Comments
 (0)