🌐
Mypy
mypy.readthedocs.io › en › stable › cheat_sheet_py3.html
Type hints cheat sheet - mypy 2.4.0 documentation
This document is a quick cheat sheet showing how to use type annotations for various common types in Python.
🌐
Pybites
pybit.es › articles › code-better-with-type-hints-part-2
Code Better with Type Hints – Part 2 – Pybites
August 27, 2021 - So, when you want to type annotate a list and its elements, use list[<type>], for example list[int] for a list of integers or list[str] for a list of strings or even list[list[int]] for a nested list of integers (and remember, that, previous ...
🌐
mypy
mypy.readthedocs.io › en › latest › cheat_sheet_py3.html
Type hints cheat sheet - mypy 2.5.0+dev.eb8cc4d05fde5c12194d929ace755807db4a3748 documentation
This document is a quick cheat sheet showing how to use type annotations for various common types in Python.
🌐
Readthedocs
coatl-mypy.readthedocs.io › en › v0.971 › cheat_sheet.html
Type hints cheat sheet (Python 2) - mypy 0.971 documentation
So many of the examples have a dual purpose: show how to write the annotation, and show the inferred types. ... To check Python 2 code with mypy, you’ll need to install mypy with pip install 'mypy[python2]'. from typing import List, Set, Dict, Tuple, Text, Optional # For simple built-in types, just use the name of the type x = 1 # type: int x = 1.0 # type: float x = True # type: bool x = "test" # type: str x = u"test" # type: unicode # For collections, the name of the type is capitalized, and the # name of the type inside the collection is in brackets x = [1] # type: List[int] x = {6, 7} # t
🌐
Python Snacks
pythonsnacks.com › python snacks › a cheat sheet for type hinting in python
A Cheat Sheet for Type Hinting in Python
July 3, 2025 - To specify type hinting, each parameter in the function is followed by a colon (:) with the respective data type (i.e. str, int, list).
🌐
Bruceho
bruceho.dev › python › type-hint-cheatsheet
Type Hint Cheat Sheet
# Most type checkers can infer the type of a variable from its value x: int = 1 x: float = 1.0 x: bool = True x: str = "String" x: bytes = b"Bytes" # In Python 3.9+ x: list[int] = [1, 2] x: set[int] = {5, 6} # For tuples of fixed size x: tuple[int, ...
🌐
Medium
medium.com › depurr › python-type-hinting-a7afe4a5637e
Python Type Hinting. Beginner’s Cheat Sheet | by Debanga Raj Neog, Ph.D | Depurr | Medium
May 18, 2020 - To statically type built-in data structure we can use typing package as follows. from typing import List, Set, Dict, Tuple, Optional
🌐
Python documentation
docs.python.org › 3 › library › typing.html
typing — Support for type hints
1 week ago - While type hints can be simple classes like float or str, they can also be more complex. The typing module provides a vocabulary of more advanced type hints. New features are frequently added to the typing module. The typing_extensions package provides backports of these new features to older versions of Python. See also · Typing cheat sheet ·
🌐
GitHub
github.com › vyahello › python-type-hints-cheetsheet
GitHub - vyahello/python-type-hints-cheetsheet: 📚 Contains a set of tips and tricks for python annotations
# own_type.py from typing import List, NewType, TypeVar Position = NewType("Position", int) IntOrStr = TypeVar("IntOrStr", int, str) some_position = Position(10) + Position(7) def count_number_of_element( container: List[IntOrStr], element: IntOrStr ) -> int: return container.count(element) print(some_position) print(count_number_of_element([1, 1, 2, "foo", "bar", 1], 1)) ... # mypy.ini [mypy] python_version = 3.6 warn_no_return = True warn_return_any = True warn_unused_configs = True disallow_any_expr = True show_column_numbers = True show_error_context = True
Author: vyahello
Find elsewhere
🌐
Kuniga
kuniga.me › docs › python › types.html
Python Type Hints Cheatsheet
We cannot provide a description for this page right now
🌐
Molssi
education.molssi.org › type-hints-pydantic-tutorial › chapters › TypeHintsInPython.html
Type Hints in Python — Python Type Hints, Dataclasses, and Pydantic
There is an important point to make about the difference between list and tuple as type hint. list are considered mutable objects in Python, so in our example the list[str] hint indicates the “list is of arbitrary length and every object is a string.” Because of this, list only accepts ...
🌐
Wamaithanyamu
wamaithanyamu.com › python-lists
Using Lists in python with type hints
December 31, 2022 - Lists are a built-in data type in Python used to store multiple items in a single variable and are initialized in two ways : ... # Import the type hint module # Any means the List will take in any type of data type from typing import List, Any # Initialised using square brackets my_empty_list: List[Any] = [] print(my_empty_list) my_list_of_integers: List[int] = [1,2,3,4] print(my_list_of_integers) my_list_of_floats: List[float] = [1.2, 3.4, 5.6] print(my_list_of_floats) my_list_of_strings: List[str] =["this", "is" ,"a" ,"string"] print(my_list_of_strings) my_list_of_booleans: List[bool] =[True,False,False,True] print(my_list_of_booleans) my_mixed_list: List[Any] = [1, "Hello", False, 1.23] print(my_mixed_list)
🌐
Cheatography
cheatography.com › mrbeverage › cheat-sheets › python-type-hints › pdf pdf
Python Type Hints Cheat Sheet by MrBeverage
Python Type Hints Cheat Sheet · ... String · s: bytes = b"te​st" Bytes · Explicit Collec​tions (from typing import ...) x: List[int] = [1] Explicitly typed list ·...
🌐
Arunkprasad
arunkprasad.com › log › python-type-hints-cheat-sheet
Python Type Hints Cheat Sheet | Arun Prasad
Quick reference for Python 3.9+. For greater detail, see this cheat sheet.
🌐
Python
docs.python.org › 3.10 › library › typing.html
typing — Support for type hints — Python 3.10.22 documentation
The argument list must be a list of types or an ellipsis; the return type must be a single type. There is no syntax to indicate optional or keyword arguments; such function types are rarely used as callback types. Callable[..., ReturnType] (literal ellipsis) can be used to type hint a callable ...
🌐
Readthedocs
coatl-mypy.readthedocs.io › en › v0.971 › cheat_sheet_py3.html
Type hints cheat sheet (Python 3) - mypy 0.971 documentation
# This is how you declare the type of a variable type in Python 3.6 age: int = 1 # You don't need to initialize a variable to annotate it a: int # Ok (no value at runtime until assigned) # The latter is useful in conditional branches child: bool if age < 18: child = True else: child = False · from typing import List, Set, Dict, Tuple, Optional # For simple built-in types, just use the name of the type x: int = 1 x: float = 1.0 x: bool = True x: str = "test" x: bytes = b"test" # For collections, the type of the collection item is in brackets # (Python 3.9+) x: list[int] = [1] x: set[int] = {6,
Top answer
1 of 5
347

As of May 2015, PEP 484 (Type Hints) has been formally accepted. The draft implementation is also available at github under ambv/typehinting.

In September 2015, Python 3.5 was released with support for Type Hints and includes a new typing module. This allows for the specification of types contained within collections. As of November 2015, JetBrains PyCharm 5.0 fully supports Python 3.5 to include Type Hints as illustrated below.

from typing import List

def do_something(l: List[str]):
    for s in l:
        s  # str

Original Answer

As of Aug 2014, I have confirmed that it is not possible to use Python 3 type annotations to specify types within collections (ex: a list of strings).

The use of formatted docstrings such as reStructuredText or Sphinx are viable alternatives and supported by various IDEs.

It also appears that Guido is mulling over the idea of extending type annotations in the spirit of mypy: http://mail.python.org/pipermail/python-ideas/2014-August/028618.html

2 of 5
230

As of Python 3.9, builtin types are generic with respect to type annotations (see PEP 585). This allows to directly specify the type of elements:

def my_func(l: list[int]):
    pass

This also extends to most other container types of the standard library, for example collections.deque or collections.abc.Mapping.


Various tools may support this syntax earlier than Python 3.9. When annotations are not inspected at runtime, the syntax is valid using quoting or __future__.annotations.

# quoted
def my_func(l: 'list[int]'):
    pass
# postponed evaluation of annotation
from __future__ import annotations

def my_func(l: list[int]):
    pass

As a consequence of PEP 585, most helpers in typing corresponding to standard library types are deprecated, such as typing.List, typing.Deque or typing.Mapping. They should only be used if compatibility with Python versions prior to 3.9 is required.

🌐
Kaggle
kaggle.com › code › debanga › beginner-s-cheat-sheet-to-python-type-hinting
Beginner's Cheat Sheet to Python Type Hinting | Kaggle
May 18, 2020 - Explore and run AI code with Kaggle Notebooks | Using data from No attached data sources
🌐
Towards Data Science
towardsdatascience.com › home › latest › modernize your sinful python code with beautiful type hints
Modernize Your Sinful Python Code with Beautiful Type Hints | Towards Data Science
March 5, 2025 - Unfortunately, the obvious approach (to write list) is not valid in Python version 3.8 and lower 😒 · You actually need to reach into the built-in module typing ** to grab the type hint for a list.
🌐
flycoolman
flycoolman.com › coding › python › list-tuple-dict-vs-list-tuple-dict
list, tuple, dict vs List, Tuple, Dict | flycoolman
October 4, 2020 - You should always pick then non-typing generics whenever possible as the old typing.Tuple, typing.List and other generics are deprecated and will be removed in a later version of Python. What are type hints in Python 3.5? PEP 585 – Type Hinting Generics In Standard Collections typing — Support for type hints Using List/Tuple/etc.