サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
大谷翔平
mypy.readthedocs.io
Type hints cheat sheet¶ This document is a quick cheat sheet showing how to use type annotations for various common types in Python. Variables¶ Technically many of the type annotations shown below are redundant, since mypy can usually infer the type of a variable from its value. See Type inference and type annotations for more details. # This is how you declare the type of a variable age: int = 1
# For most types, just use the name of the type in the annotation # Note that mypy can usually infer the type of a variable from its value, # so technically these annotations are redundant x: int = 1 x: float = 1.0 x: bool = True x: str = "test" x: bytes = b"test" # For collections on Python 3.9+, the type of the collection item is in brackets x: list[int] = [1] x: set[int] = {6, 7} # For mappings
Welcome to mypy documentation!¶ Mypy is a static type checker for Python. Type checkers help ensure that you’re using variables and functions in your code correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will warn you when you use those types incorrectly. Python is a dynamic language, so usually you’ll only see errors in your code when you attempt to run it. Mypy is
このページを最初にブックマークしてみませんか?
『mypy.readthedocs.io』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く