3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonの変数アノテーション

3
Posted at

変数アノテーションとはPythonで変数の型を明示的に書く方法。
よく忘れるので書き方をメモしておく。

基本

def test_func(x: bool, y: str)-> int:
    if x == True:
        return 0
    if y == "a":
        return 1
    return -1

リスト、タプル

from typing import List
from typing import Tuple

def test_func(x: List[int, int])-> Tuple[float, float]:
    return (x[1] + 0.5, x[0] - 0.5)
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?