- 最終更新
- 2026/08/17
3秒でわかる
Python で値が存在しないことだけを表す専用の値。未設定を 0 や空文字と区別するために使い、判定は is で行います。
30秒図解
もう少し詳しく
どういうものか
None は Python でget で
なぜ必要か
「まだ
具体例
def find_user(users, name):
for u in users:
if u["name"] == name:
return u
return None # 見つからなかった
user = find_user(users, "sato")
if user is None:
print("該当なし")
else:
print(user["age"])つまずきやすいところ
判定を == でis None を使う。== はクラス側で
もうAttributeError で、'NoneType' object has no attribute というlist.sort() や list.append() はx = lst.sort() と書くと x が
似た用語との違い
| 値 | 意味 | 真偽値として |
|---|---|---|
| None | 値が | 偽 |
| 0 | 数値としてのゼロ | 偽 |
| "" | 空の文字列 | 偽 |
| False | 論理値の偽 | 偽 |
すべてif not x ではif x is None と書く。
覚え方
None は


