Pythonで関数を定義する基本、位置引数やキーワード引数の渡し方と受け取り方、デフォルト引数値の指定、可変長引数の渡し方と受け取り方などを紹介する。 # パラメーターがなく、戻り値もない関数 def helloworld(): print('hello world') helloworld() # hello world # パラメーターがなく、戻り値がある関数 from datetime import datetime def get_now(): return datetime.now().strftime('%Y/%m/%d %H:%M:%S') result = get_now() print(result) # 2022/05/04 15:21:42など # パラメーターがあり、戻り値はない関数 def hello(whom): print(f'Hello, {whom}'