In Python, a built-in is a name that every program can use without an import: functions such as print(), len(), and range(), types such as int and list, the constants True, False, and None, and all the built-in exceptions.
They all live in a module called builtins. When Python looks up a name, it checks the local scope, then any enclosing functions, then the module's globals, and finally builtins. That last step is why len("abc") works in an empty file.
Writing list = [1, 2] hides the built-in list for the rest of that scope, and a later list("abc") raises TypeError. Pick names like items or numbers instead.
Syntax
Python Syntax
Call a built-in by name with its arguments in parentheses:
Python
words = ["pear", "fig", "apple"]
count = len(words) # 3: a function returning an int
first = sorted(words)[0] # "apple": a new sorted list
number = int("15") # 15: calling the int type
pairs = list(enumerate(words)) # [(0, 'pear'), (1, 'fig'), ...]
print(count, first, number) # 3 apple 15
Reference
Built-in Functions vs Built-in Types
The list of built-ins mixes two kinds of callables. You use them the same way, but they behave a little differently:
Usually written as @property above a method inside a class
Constants
True, False, None
Keywords you cannot reassign
Reference
How to See Every Built-in
Import the builtins module and pass it to dir(). The full list is long and changes between Python versions, so filter it instead of printing everything. The name __builtins__ also refers to the built-ins in most programs, but it is an implementation detail; import builtins is the reliable way.
Python
import builtins
names = dir(builtins)
print("len" in names) # True
print("sqrt" in names) # False: math.sqrt needs an import
print(builtins.len is len) # True: the same object
print(len(names) > 100) # True on every modern Python
For help on any one of them, call help(), for example help(len), or open its guide from the index.
Code
Python Examples
Three short programs that show how built-ins fit into everyday Python.
words = ["banana", "Apple", "cherry", "date"]
print(len(words), sorted(words, key=str.lower))
print(max(words, key=len), min(len(w) for w in words))
print(sum(len(w) for w in words), list(enumerate(words[:2], 1)))
Always available. Every function used here is a built-in, so the script needs no import line.
Key functions.sorted(..., key=str.lower) ignores case and max(..., key=len) picks the longest word; banana wins the tie with cherry because it comes first.
Generators as input.min() and sum() accept generator expressions directly: the shortest word has 4 letters and the total is 21.
Lazy results.enumerate() returns an iterator, so list() is used to show its pairs.
Example 2 — Built-in Functions and Built-in Types
Use float(), int(), str(), and bool() as converters, then check what kind of object each built-in is.
Python
raw = ["42", "3.5", "", "7"]
numbers = [float(x) for x in raw if x]
print(numbers)
print(int(numbers[0]), str(numbers[1]), bool(raw[2]))
print(type(len).__name__, type(int).__name__)
print(isinstance(int("7"), int), callable(int))
Output
[42.0, 3.5, 7.0]
42 3.5 False
builtin_function_or_method type
True True
How It Works
Types convert. Calling the type float turns each non-empty string into a number.
Truthiness.bool("") is False, which is also why the comprehension's if x skipped the empty string.
Two kinds of built-in.len is a plain built-in function, while int is a class whose type is type.
Example 3 — Shadowing a Built-in and Getting It Back
Hide the built-in list with a variable, see the error, and restore it.
Python
import builtins
list = [1, 2, 3]
try:
list("abc")
except TypeError:
print("list now refers to a list object, not the type")
del list
print(list("abc"))
print(builtins.list is list)
Output
list now refers to a list object, not the type
['a', 'b', 'c']
True
How It Works
Lookup order. Python checks local, then global, then built-in names, so the global list wins.
Not callable. A list object cannot be called, so list("abc") raises TypeError.
Delete the global.del list removes the variable, and the built-in becomes visible again.
The builtins module.builtins.list always refers to the real type, even while it is shadowed.
A built-in function is a function that Python provides automatically, such as print(), len(), and range(). You can call it in any program without importing anything, because it lives in the builtins module that Python loads at startup.
They are classes (built-in types). Calling a class creates a new object, so int("7") builds an int and list("ab") builds a list. Because you call them the same way, Python documents them together with the built-in functions.
Run import builtins and then dir(builtins). The list includes the functions and types plus constants such as True and None and every built-in exception class. The exact list depends on your Python version.
Your variable shadows the built-in for the rest of that scope, so a later list(...) call fails. Avoid names like list, dict, str, sum, and id for variables. If it happens, del the variable or use builtins.list.
Run the examples on this page, then open the Built-in Functions index for print(), len(), sorted(), and every other guide in this Python tutorial series.