Built-in typesΒΆ
These are examples of some of the most common built-in types:
Type |
Description |
|---|---|
|
integer |
|
floating point number |
|
boolean value (subclass of |
|
string (unicode) |
|
8-bit string |
|
an arbitrary object ( |
|
list of |
|
tuple of two |
|
tuple of an arbitrary number of |
|
dictionary from |
|
iterable object containing ints |
|
sequence of booleans (read-only) |
|
mapping from |
|
dynamically typed value with an arbitrary type |
The type Any and type constructors such as List, Dict,
Iterable and Sequence are defined in the typing module.
The type Dict is a generic class, signified by type arguments within
[...]. For example, Dict[int, str] is a dictionary from integers to
strings and Dict[Any, Any] is a dictionary of dynamically typed
(arbitrary) values and keys. List is another generic class. Dict and
List are aliases for the built-ins dict and list, respectively.
Iterable, Sequence, and Mapping are generic types that
correspond to Python protocols. For example, a str object or a
List[str] object is valid
when Iterable[str] or Sequence[str] is expected. Note that even though
they are similar to abstract base classes defined in collections.abc
(formerly collections), they are not identical, since the built-in
collection type objects do not support indexing.