I am confused about the term "built-in" function. I thought it meant only those functions built into the interpreter and documented in - 2. Built-in Functions
But it appears that functions defined in standard library modules are also built-in functions (in some cases). For example -
>>> import os >>> os.chdir <built-in function chdir> >>> import warnings >>> warnings.warn <built-in function warn> >>> import json >>> json.dumps <function dumps at 0x7f3643a240d0> # not built-in >>> dir <built-in function dir> >>>
So when is a function in a standard library module called a built-in function and when is it not?
The Python built-in functions are defined as the functions whose functionality is pre-defined in Python. The python interpreter has several functions that are always present for use. These functions are known as Built-in Functions.
Using Python built-in function help(), we can obtain the list of built-in modules available in Python.
The Python Standard Library contains the exact syntax, semantics, and tokens of Python. It contains built-in modules that provide access to basic system functionality like I/O and some other core modules. Most of the Python Libraries are written in the C programming language.
Built-in functions are ones for which the compiler generates inline code at compile time. Every call to a built-in function eliminates a runtime call to the function having the same name in the dynamic library.
There are two meanings of “built-in” here, although they both mean “part of the interpreter”. The library reference uses it to indicate that a function is available without an import
(it is “not part of a module”, although see builtins
). The interpreter itself uses it to indicate that a function is implemented natively rather than in Python (in CPython, it is at least nominally implemented in C).
There is yet another meaning on the C side: an extension module (i.e., one written in C) is built-in if the Python binary incorporates it rather than loading it if and when needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With