Python3.7予約語またはkeyword一覧と組み込み関数取得・確認方法

Python3.7予約語またはキーワード一覧

予約語、または Python 言語における キーワード (keyword) として使われ、通常の識別子(変数名・関数名・クラス名)として使うことはできない字句です。予約語そのものは35と少ないのですが、始めからPythonには組み込み関数などがありこの関数も変数の使用は避けたい字句です。

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

Pythonの予約語または、キーワードの取得方法

Pycharmのターミナルから取得する

__import__('keyword').kwlist

と入力すると以下のように確認ができます。

pycharmのファイルから取得(確認)する

import keyword
print(keyword.kwlist)

とPycharmのファイルに入力すると以下の画像のように確認可能です。

識別子として使えるけれども使わない方がいい文字列(組み込み関数)

Pythonには、始めから、組み込まれている関数があります。この関数を変数名などに使うのは混乱のもととなるので避けたい字句ですね。

まず、取得した組み込み関数は以下の通りです。

Pycharmのターミナルから取得する方法

dir(__builtins__)

と入力すると以下のように沢山出力されました。

['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedErro
r', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'File
NotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryErr
or', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError',
 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsy
ncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', '
UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__build_class__', '__debug_
_', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'cl
assmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', '
globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'obj
ect', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple'
, 'type', 'vars', 'zip']

かなり沢山ありますね!!
こんなに沢山覚えていられないので、プログラミングの途中でも確認しやすい方法を紹介しておきます。

Pycharmのファイルから確認する方法

import builtins
builtins.

と入力すると以下のように参照できますので、その都度確認するのが効率的かもしれませんね。

Python組み込み関数の詳しい説明はhttps://docs.python.org/ja/3.7/library/functions.html#built-in-funcs
から確認してください。

スポンサーリンク
スポンサーリンク
SNSフォローボタン

フォローする

シェアする

  • このエントリーをはてなブックマークに追加
スポンサーリンク
スポンサーリンク