2
2

More than 1 year has passed since last update.

Python アノテーションとは?

Last updated at Posted at 2022-03-10

概要

1: アノテーションとは?
2: 使い方

1: アノテーションとは?

アノテーションとは、関数の戻り値の型(Decimal, string, int など)が何で返ってくるか示した注釈のようなもの。
使用することで、コーディングした人がどの型を想定してコーディングしたかを読み手に示すことができる。

※前提:pythonでは、型を指定することは不要

2: 使い方

  • 通常の関数
def function (arg1, arg2, ..) :
    ・・・・
  • アノテーション使用した関数
def function (arg1, arg2, ..) -> "戻り値の型名":
    ・・・・

例)

def calc (number_1, number_2) -> int:
    return number_1 + number_2
2
2
1

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
2
2