AI engineering glossary · Python advanced
What is typeVar?
TypeVar: A construct from the typing module that creates a placeholder type used to link types across a signature. It expresses that the output type depends on the input type. Together with Generic it underpins reusable, type-safe helpers.
TypeVar: an example
T = TypeVar('T'); def first(xs: list[T]) -> T: tells checkers that first on a list of strings returns a string.
Related terms
More Python advanced terms
Where you learn it
TypeVar is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.