it:programmiersprache:python:typehints

Python Typehints

ab Python 3.10 PEP 604 – Allow writing union types as X | Y

int str …

Check

from typing import NewType
 
RGB = NewType("RGB", tuple[int, int, int])

Check

from typing import TypeVar
 
TypeVar .....                                 # < 3.12
def funktion[T](items: list[T]) -> T:         # ab 3.12

Notizen

ab Python 3.5 (PEP 484 – Type Hints)

Any, Union, Tuple, Callable TypeVar, Generic
Dict, List

<neuer Typ> = NewType('<neuer Name>', int)

  • it/programmiersprache/python/typehints.txt
  • Zuletzt geändert: 25.09.2026 20:08
  • von marsch