Generics

Generics — typing documentation https://typing.python.org/en/latest/reference/generics.html

You may have seen type hints like list[str] or dict[str, int] in Python code. These types are interesting in that they are parametrised by other types! A list[str] isn’t just a list, it’s a list of strings. Types with type parameters like this are called generic types.

You can define your own generic classes that take type parameters, similar to built-in types such as list[X]. Note that such user-defined generics are a moderately advanced feature and you can get far without ever using them.



posted @ 2025-09-11 10:50  papering  阅读(8)  评论(0)    收藏  举报