Python Built-in Types
Contents
ByteArray
Bytes
Complex
Dict
In the context of type annotations, try:
d: dict[str, int] = {"1": 1}
Float
FrozenSet
In the context of type annotations, try:
def __init__(self) --> None: self._options: frozenset[str] = frozenset([1, 2])
Int
List
In the context of type annotations, try:
l: list[str] = ["ham", "spam"]
MemoryView
Set
In the context of type annotations, try:
s: set[str] = set(["A", "B", "A"])
Str
Tuple
In the context of type annotations, try:
single: tuple[int] = [1] double: tuple[int, int] = [1, 2] nple: tuple[int, ...] = [1, 2, 3, 4, 5]
The tuple[T, ...] annotation checks for homogenous typing. To allow for a a variable number of any values, try:
from typing import Any something: tuple[Any, ...] = [1, "1"]