Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is a function in a standard library module called a built-in function?

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?

like image 321
debashish Avatar asked Apr 10 '18 14:04

debashish


People also ask

What is a built-in function in Python?

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.

Which function is used to list builtin functions in a module?

Using Python built-in function help(), we can obtain the list of built-in modules available in Python.

What is built-in libraries 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.

What are built-in functions?

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.


1 Answers

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.

like image 174
Davis Herring Avatar answered Sep 20 '22 22:09

Davis Herring