Skip to main content

Built-in functions

The builtins module is the implicit base of every name lookup. It holds the always-available functions, constants, and exception classes. This page is the complete catalogue.

Source-of-record: Python/bltinmodule.c, the built-in functions reference.

Functions

Object inspection and construction

FunctionBehaviour
type(object) / type(name, bases, dict)Get type, or construct a class.
isinstance(obj, type_or_tuple)Type test.
issubclass(cls, type_or_tuple)Subtype test.
id(obj)Identity number.
hash(obj)Compute hash.
repr(obj)Canonical string.
ascii(obj)repr with non-ASCII escaped.
dir([obj])Attribute listing.
vars([obj])__dict__ of obj.
callable(obj)True if tp_call is set.
hasattr(obj, name)True if getattr would succeed.
getattr(obj, name[, default])Attribute lookup.
setattr(obj, name, value)Attribute set.
delattr(obj, name)Attribute delete.
object()Bare object.

Numeric

FunctionBehaviour
abs(x)Absolute value (__abs__).
divmod(a, b)(a // b, a % b).
pow(base, exp[, mod])base ** exp or modular exponentiation.
round(number[, ndigits])Banker's rounding.
min(iter, *, key=None, default=...) / min(*args)Minimum.
max(iter, *, key=None, default=...) / max(*args)Maximum.
sum(iter[, start])Sum elements.
bool([x])Convert to bool.
int([x[, base]])Convert to int.
float([x])Convert to float.
complex([real[, imag]])Construct complex.
bin(x) / oct(x) / hex(x)Integer representation strings.

Sequence and iteration

FunctionBehaviour
len(s)__len__.
iter(obj[, sentinel])Get iterator.
next(it[, default])Advance iterator.
reversed(seq)Reverse iterator.
sorted(iter, *, key=None, reverse=False)New sorted list.
enumerate(iter, start=0)(index, value) pairs.
zip(*iters, strict=False)Tuples from each iterable.
map(fn, *iters)Apply fn lazily.
filter(fn, iter)Keep truthy results.
range([start,] stop[, step])Lazy arithmetic progression.
slice([start,] stop[, step])Construct slice object.
tuple([iter])Tuple from iterable.
list([iter])List from iterable.
dict([mapping_or_iter], **kwargs)Dict construction.
set([iter])Set from iterable.
frozenset([iter])Frozenset from iterable.
bytes([source[, encoding[, errors]]])Bytes from iterable/str/int.
bytearray([source[, encoding[, errors]]])Mutable bytes.
memoryview(obj)Buffer view.
str([object[, encoding[, errors]]])Convert to str.
any(iter)Short-circuit truthy.
all(iter)Short-circuit falsy.

I/O and execution

FunctionBehaviour
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)Print.
input([prompt])Read a line.
open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)Open a file.
exec(source, globals=None, locals=None, *, closure=None)Compile and run.
eval(source, globals=None, locals=None)Evaluate expression.
compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)Produce a code object.
__import__(name, globals=None, locals=None, fromlist=(), level=0)Backend of import.

Class machinery

FunctionBehaviour
classmethod(fn)Descriptor: bind to class.
staticmethod(fn)Descriptor: bypass self.
property(fget=None, fset=None, fdel=None, doc=None)Managed attribute.
super([type[, object_or_type]])Cooperative method lookup.
__build_class__(func, name, *bases, **kwds)Implementation of class statement.

Formatting

FunctionBehaviour
format(value, format_spec='')Call __format__.
repr(obj)Canonical string.
chr(int)Code point -> character.
ord(char)Character -> code point.

Hashing and identity

FunctionBehaviour
hash(obj)Compute hash via __hash__.
id(obj)Identity number.
globals()Module-level namespace.
locals()Active local namespace.
breakpoint(*args, **kwargs)Call sys.breakpointhook.

Constants

NameValue
TrueThe truthy singleton.
FalseThe falsy singleton.
NoneThe unit singleton.
NotImplementedSentinel returned by binary operators.
Ellipsis (...)Singleton.
__debug__True unless run under -O.
__name__'__main__' in script context.
__doc__Module docstring.
__package__Containing package name.
__spec__Module spec.
__loader__Loader instance.
__file__Source file path.
__builtins__Builtins reference inside other modules.
copyright / credits / license / help / exit / quitInteractive helpers installed by site.py.

Classes exposed via builtins

The classes corresponding to every built-in type are also available by name from builtins:

bool, bytearray, bytes, complex, dict, ellipsis, enumerate, filter,
float, frozenset, int, list, map, memoryview, object, property,
range, reversed, set, slice, staticmethod, str, super, tuple, type,
zip, classmethod

Plus the exception hierarchy (see Built-in exceptions).

Argument-clinic-style signatures

Many builtins are written with positional-only and keyword-only markers. The full signatures are documented in Python/clinic/bltinmodule.c.h. Examples:

abs($module, x, /)
print($module, /, *args, sep=' ', end='\n', file=None, flush=False)
sorted($module, iterable, /, *, key=None, reverse=False)
zip($module, /, *iterables, strict=False)
min($module, /, *args, default=<unrepresentable>, key=None)

The leading $module is the implicit module argument. / marks positional-only; * marks the start of keyword-only.

Exception classes

Every exception class listed in Built-in exceptions is available from builtins.

Gopy status

Function or constant groupState
All built-in functions listed aboveComplete.
All constantsComplete.
All built-in classesComplete.
All exception classesComplete.
input line editingFalls back to bare reads when stdin is not a TTY; rlwrap recommended.

Reference