関数
関数を定義する
https://docs.python.org/ja/3/reference/compound_stmts.html#function-definitions
def キーワードで関数を定義する。
code:py
def 関数名(引数1, 引数2, ...):
文1
文2
return 式
関数の結果は return 文で返す。
code:py
def sum_two_numbers(a, b):
return a + b
https://docs.python.org/ja/3/glossary.html#term-function-annotation
型を明示することができる。関数アノテーション(function annotation)と呼ばれる。
code:py
def sum_two_numbers(a: int, b: int) -> int:
return a + b
関数を使う
code:py
関数名(引数1, 引数2, ...)
作った関数を別のファイルから呼び出したい場合
code:py
from モジュール名 import 関数名
関数名(引数1, 引数2, ...)
モジュール名はモジュールの階層構造でドット記法になっている。
インポート
Keyword: サブルーチン