A function that returns the first item of a list gives back a string if you give it strings, and a number if you give it numbers. A hint of Any would lose that link, and a hint of one fixed type would be wrong. Generics fix this: a type variable stands for whatever type is used, and the checker keeps track of it. This lesson shows how to write generic functions and classes, in the older style that works everywhere and the newer style from Python 3.12.
More lessons in Complete Python Programming