About 124,000 results
Open links in new tab
  1. Generics — typing documentation

    Generics ¶ 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. …

  2. Python Generics - GeeksforGeeks

    Oct 29, 2025 · Python Generics Example Below, are examples of Python Generics in Python. Example 1: Python Generics with Function In this example, the below code defines a generic function element …

  3. Generics — typing documentation

    This is equivalent to omitting the generic notation and just saying elements: list. User-defined generic types ¶ There are several ways to define a user-defined class as generic: Include a Generic base …

  4. The Complete Guide to Python Generics: From Beginner to Pro

    Python Generics might sound intimidating, but they’re actually one of the most powerful features for writing clean, reusable, and type-safe…

  5. Generics - mypy 2.1.0 documentation

    There are two syntax variants for defining generic classes in Python. Python 3.12 introduced a new dedicated syntax for defining generic classes (and also functions and type aliases, which we will …

  6. Python 3.12 Generics: Cleaner, Easier Type-Hinting - ArjanCodes

    Jun 6, 2024 · Learn how Python 3.12 generics make type-hinting easier and clearer. Use the new syntax to enhance your code's structure and readability.

  7. New syntax of Python generics - Stack Overflow

    Jan 6, 2025 · The Python compiler will translate the new generic syntax into a form similar to the one above, or wrap it in a similar form of other functions. In fact, the ultimate code for creating generics is …

  8. Python Generic Types: A Comprehensive Guide - CodeRivers

    Apr 13, 2025 · Python is a dynamic, strongly-typed language. While it has always been possible to write code that works with different types in a flexible way, the introduction of generic types in Python 3.5+ …

  9. 9. Generics - Thinking in Types

    Generics Generics in Python produce flexible, reusable code that remains type-safe. They enable the definition of classes, functions, and types that can operate on a variety of types while preserving type …

  10. Using Generics in Python. If you are using type hints in ... - Medium

    Jul 21, 2021 · If you are using type hints in Python and static analysis tools such as mypy, then you have probably used the Any type quite often to get…