Language Syntax

Type parameter list — Python syntax

Declare scoped generic parameters for functions, classes or type aliases. Introduced in 3.12; type parameter defaults were added in 3.13. Parameters describe typing contracts and do not automatically validate call arguments. A colon can specify a bound or constraints for a type variable; *Ts and **P declare variadic type parameters and parameter specifications.

Formal Syntax & Structure

python syntaxpython
def identity[T](value: T) -> T:    suiteclass Box[T]:    suitetype Alias[T] = expression

Working Example

Example Snippetpython
def identity[T](value:T)->T:    return valueprint((identity(7),identity.__type_params__[0].__name__))
Python Reference