- 読み方
- ひきすう
- 最終更新
- 2026/10/14
3秒でわかる
関数を呼び出すときに渡す値のこと。受け取る側の仮引数に対応づけて処理へ持ち込み、同じ処理を違う値で何度も使い回せるようにします。
30秒図解
引数をたとえると?
自動販売機に
もう少し詳しく
引数は、
まず、よくある誤解
誤解 「関数の
本当は Python では
どういうものか
引数は、
渡し方は
なぜ必要か
引数が
キーワード引数には
具体例
def price_with_tax(amount, rate=0.1, *, round_down=True):
total = amount * (1 + rate)
return int(total) if round_down else round(total, 2)
print(price_with_tax(1000)) # 1100 位置引数だけ
print(price_with_tax(1000, 0.08)) # 1080 税率を位置で
print(price_with_tax(1000, rate=0.08)) # 1080 税率を名前で
print(price_with_tax(1000, round_down=False)) # 1100.0 名前指定が必須の引数* より
つまずきやすいところ
デフォルト値に
def add_item(item, cart=None):
if cart is None:
cart = []
cart.append(item)
return cartNone を
もう 1 つは、
覚え方
「関数の

