LoginSignup
1
1

More than 3 years have passed since last update.

【Udemy Python3入門+応用】 49. 関数の引用と返り値の宣言

Posted at

※この記事はUdemyの
現役シリコンバレーエンジニアが教えるPython3入門+応用+アメリカのシリコンバレー流コードスタイル
の講座を受講した上での、自分用の授業ノートです。
講師の酒井潤さんから許可をいただいた上で公開しています。

■関数の引用と返り値の宣言

function
# a,b,返り値をint型とし、a+bを返す
def add_num(a: int, b: int) -> int:
    return a + b

r = add_num(10, 20)
print(r)
result
30

Python3.6以降では、
num: int = 10
とすると、
num = 10で、かつnumはint型にする」、
というように記述できた。

-> intとしているのは、
「返り値もint型にする」
という意味。

こういう風にする場合は多くはないが、
このような記述をする場合もあるため、頭の片隅に入れておこう。

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