予約語とは
あらかじめプログラミング言語で登録されている単語で
コード中では特別な意味を持つので
変数名に使えない単語です
これを実行してもらうと 、予約語一覧が出ます
これらの単語は意味を持つので
使えない単語として覚えておきましょう
その他にも気をつけたい単語があります
list は変数名としても使えますが
組み込み関数として使われているので
変数名にしてしまうと上書きしてしまい
list関数が使えなくなってしまいます
関数一覧はこれで見れます
これらの単語を変数名に使うと
思わぬところでエラーが発生し実行できなくなるので
使わないようにしましょう
もし使ってしまって
実行寺にエラーが発生した場合は
jupyter notebook を再起動しましょう
あらかじめプログラミング言語で登録されている単語で
コード中では特別な意味を持つので
変数名に使えない単語です
これを実行してもらうと 、予約語一覧が出ます
__import__('keyword').kwlist
['False',
'None',
'True',
'and',
'as',
'assert',
'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']
これらの単語は意味を持つので
使えない単語として覚えておきましょう
その他にも気をつけたい単語があります
list は変数名としても使えますが
組み込み関数として使われているので
変数名にしてしまうと上書きしてしまい
list関数が使えなくなってしまいます
関数一覧はこれで見れます
dir(__builtins__)
'ArithmeticError',
'AssertionError',
'AttributeError',
'BaseException',
'BlockingIOError',
'BrokenPipeError',
'BufferError',
'BytesWarning',
'ChildProcessError',
'ConnectionAbortedError',
'ConnectionError',
'ConnectionRefusedError',
'ConnectionResetError',
'DeprecationWarning',
'EOFError',
'Ellipsis',
'EnvironmentError',
'Exception',
'False',
'FileExistsError',
'FileNotFoundError',
'FloatingPointError',
'FutureWarning',
'GeneratorExit',
'IOError',
'ImportError',
'ImportWarning',
'IndentationError',
'IndexError',
'InterruptedError',
'IsADirectoryError',
'KeyError',
'KeyboardInterrupt',
'LookupError',
'MemoryError',
'NameError',
'None',
'NotADirectoryError',
'NotImplemented',
'NotImplementedError',
'OSError',
'OverflowError',
'PendingDeprecationWarning',
'PermissionError',
'ProcessLookupError',
'RecursionError',
'ReferenceError',
'ResourceWarning',
'RuntimeError',
'RuntimeWarning',
'StopAsyncIteration',
'StopIteration',
'SyntaxError',
'SyntaxWarning',
'SystemError',
'SystemExit',
'TabError',
'TimeoutError',
'True',
'TypeError',
'UnboundLocalError',
'UnicodeDecodeError',
'UnicodeEncodeError',
'UnicodeError',
'UnicodeTranslateError',
'UnicodeWarning',
'UserWarning',
'ValueError',
'Warning',
'ZeroDivisionError',
'__IPYTHON__',
'__IPYTHON__active',
'__build_class__',
'__debug__',
'__doc__',
'__import__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'abs',
'all',
'any',
'ascii',
'bin',
'bool',
'bytearray',
'bytes',
'callable',
'chr',
'classmethod',
'compile',
'complex',
'copyright',
'credits',
'delattr',
'dict',
'dir',
'divmod',
'dreload',
'enumerate',
'eval',
'exec',
'filter',
'float',
'format',
'frozenset',
'get_ipython',
'getattr',
'globals',
'hasattr',
'hash',
'help',
'hex',
'id',
'input',
'int',
'isinstance',
'issubclass',
'iter',
'len',
'license',
'list',
'locals',
'map',
'max',
'memoryview',
'min',
'next',
'object',
'oct',
'open',
'ord',
'pow',
'print',
'property',
'range',
'repr',
'reversed',
'round',
'set',
'setattr',
'slice',
'sorted',
'staticmethod',
'str',
'sum',
'super',
'tuple',
'type',
'vars',
'zip']
これらの単語を変数名に使うと
思わぬところでエラーが発生し実行できなくなるので
使わないようにしましょう
もし使ってしまって
実行寺にエラーが発生した場合は
jupyter notebook を再起動しましょう