Pythonに組み込まれている関数と方法をメモします.

4483 ワード

Pythonでは、関数function-A series of statements which returns some value to a callerという明確な規定があります.It can also be passed zero or more arguments which may be used in the execution of the body.
方法method-A function which is defined inside a class body.If called as an attribute of an instance of that class, the method will get the instance object as its first argument (which is usually called self).
定義の観点から、関数(function)は一連の文であり、これらの文は呼び出し者にいくつかの値またはNoneを返し、理論的には他のものと関係なく、関連するパラメータだけでよいことを知っています.したがって,通常モジュールで定義される呼称関数は理にかなっている.関数はいくつかの独立した機能をカプセル化して、直接呼び出すことができて、pythonは多くの関数を内蔵して、同時に自分で関数を構築して使用することができます.一般関数フォーマット:関数名(パラメータ)
では,メソッドの意味は明確であり,あるオブジェクトと相互に関連している,すなわちその実現はあるオブジェクトと関連している.これが方法です.定義は関数と同じですが.メソッドと関数は同様に独立した機能をカプセル化しているが,メソッドはオブジェクトによって呼び出され,このオブジェクトに対する操作を表し,使用時に点メソッドを採用する必要がある.一般メソッドフォーマット:オブジェクト.方法()
dir()内蔵関数の役割
pythonの組み込み方法はたくさんありますが、初心者でもpython経由のプログラマーでもすべての方法を覚えられないので、dir()関数はとても役に立ちます.dir()関数を使用すると、対像内のすべての属と方法を表示できます.pythonでは、すべて対像、データ型、モジュールなど、独自の属性と方法があります.一般的な方法以外は、すべて覚えておく必要はありません.dir()関数に渡せばいいです.python 3でprint(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', 'ModuleNotFoundError', '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', 'WindowsError', 'ZeroDivisionError', '__build_class__', 
'__debug__', '__doc__', '__import__', '__loader__', '__name__', 
'__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 
'bytearray', 'bytes', 'callable', 'chr', 'classmethod', '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', 'object', 'oct', 'open', 'ord', 
'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 
'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']

公式3.7組み込み関数の説明(英語の説明)