December 2017
Beginner
412 pages
10h 8m
English
In addition to type annotations for built-in types such as int and str, module typing provides types List, Set, Tuple, and Dict. For each, you can specify the kind of thing it contains, including type Any for function parameters that work with a mixed set of types.
To explore this, we’ll revisit atoms and molecules from Multiline Records, using dictionaries and tuples in addition to lists.
Recall functions read_molecule and read_all_molecules; here are the headers and docstrings:
| | def read_molecule(reader: TextIO) -> list: |
| | """Read a single molecule from reader and return it, or return None to |
| | signal end of file. The first item in the result is the name of the |
| | compound; each list contains an atom ... |
Read now
Unlock full access