0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonの予約語(keyword)について

Last updated at Posted at 2025-03-23

はじめに

Pythonの予約語についてまとめてみました。

予約語とは

 Pythonには、識別子(identifier)として使用出来ない単語が35個程あり、これらは予約語(keyword)という。例えば、ifやfor、globalやwithなどは予約語であり、これらを変数名として利用することは出来ない。
識別子・・・変数などの名前として使う文字や数字の並びのこと。

予約語を調べてみる

Pythonの予約語は次のコードで調べることが出来る。

import keyword
print(keyword.kwlist)
出力結果

['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

予約語の一覧

False
None
True
and
as
assert
async
await
break
class
continue
def
del
elif
else
except
finally
for
from
global
if
import
in
is
lambda
nonlocal
not
or
pass
raise
return
try
while
with
yield

おわりに

ここまで読んでいただきありがとうございます!

参考文献

・スッキリわかるPython入門 第2版 (スッキリわかる入門シリーズ) 単行本(ソフトカバー) – 2023/11/6
国本 大悟 (著), 須藤 秋良 (著), 株式会社フレアリンク (監修)
p.52, 55

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?