0
0

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 1 year has passed since last update.

Pythonで関数を書く時に気をつけること

今回は2つの引数(整数)をとり、その和を返す関数について考える

普通の関数の書き方

def hoge(x, y):
    result = x + y
    return result

アノテーション関数

def hoge(x:int, y:int)->int:
    '''
    引数2つの和を返す
    Args
        x: 足し算に用いる値1
        y: 足し算に用いる値2
    Return
        reslt: xとyの和
    '''
    result = x + y
    return result

こうやって書くことにより、Pythonで型を指定した関数を作成することができる。
関数の返り値の型と説明があればコードの読みやすさが段違いにあがる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?