- 読み方
- かんすう
- 最終更新
- 2026/10/14
3秒でわかる
ひとまとまりの処理に名前を付けて、何度でも呼び出せるようにした部品です。同じ処理をくり返し書かずに済み、直す所も 1 か所にまとまります。
30秒図解
関数をたとえると?
料理の
もう少し詳しく
関数は、
まず、よくある誤解
誤解 「def や
本当は 関数を
どういうものか
関数は、
なぜ必要か
同じ
もう
具体例
def with_tax(price, rate=0.1):
return int(price * (1 + rate))
print(with_tax(1000)) # 1100
print(with_tax(1000, 0.08)) # 1080function withTax(price, rate = 0.1) {
return Math.floor(price * (1 + rate));
}
const withTaxArrow = (price, rate = 0.1) => Math.floor(price * (1 + rate));
console.log(withTax(1000)); // 1100
console.log(withTaxArrow(1000)); // 1100下の withTaxArrow はアロー関数という{ } で本体をwithTax と
似た用語との違い
つまずきやすいところ
print と
もう
def add(item, items=None):
if items is None:
items = []
items.append(item)
return items



