Python 3 reference · 73 entries
Python Built-in Functions
Every function built into Python 3, from abs() to zip(): always available without an import, with syntax, parameters and runnable examples.
These functions are always available: you never need to import them. Click a name for its syntax, parameters,
return value and examples you can run in your browser. Types such as int, str and list appear here too,
because calling them creates or converts values.
| Name | Description | Since |
|---|---|---|
abs() |
Return the absolute value of a number: its distance from zero, so negative numbers become positive. | 3.0 |
aiter() |
Return an asynchronous iterator for an async iterable: the async counterpart of iter(), used with async for and anext(). | 3.10 |
all() |
Return True if every item in an iterable is truthy, or if the iterable is empty. Stops at the first falsy item. | 3.0 |
anext() |
Await and return the next item from an asynchronous iterator, or a default value when it is exhausted. | 3.10 |
any() |
Return True if at least one item in an iterable is truthy. Returns False for an empty iterable and stops at the first truthy item. | 3.0 |
ascii() |
Return a printable representation of an object, like repr(), but with every non-ASCII character escaped. | 3.0 |
bin() |
Convert an integer to a binary string prefixed with 0b, such as bin(5) giving '0b101'. Negative numbers get a minus sign. | 3.0 |
bool() |
Convert a value to True or False using Python's truth rules: zero, empty and None are False, everything else is True. | 3.0 |
breakpoint() |
Pause the program and open the debugger at this line. It calls sys.breakpointhook(), which starts pdb by default. | 3.7 |
bytearray() |
Create a mutable sequence of bytes (integers 0–255). Like bytes, but you can change, append and remove bytes in place. | 3.0 |
bytes() |
Create an immutable sequence of bytes: raw binary data such as file contents, network messages or encoded text. | 3.0 |
callable() |
Return True if an object can be called like a function: functions, classes, methods and objects with __call__(). | 3.2 |
chr() |
Return the one-character string for a Unicode code point, such as chr(65) giving 'A'. The inverse of ord(). | 3.0 |
classmethod() |
Turn a method into a class method that receives the class (cls) instead of an instance. Usually written as @classmethod. | 3.0 |
compile() |
Compile source code into a code object that exec() or eval() can run. Mostly used by tools, REPLs and teaching examples. | 3.0 |
complex() |
Create a complex number from a real and an imaginary part, or parse one from a string such as '1+2j'. | 3.0 |
delattr() |
Delete a named attribute from an object. delattr(obj, 'name') does the same as del obj.name when the name is in a variable. | 3.0 |
dict() |
Create a dictionary: a mapping of keys to values. Build it from keyword arguments, pairs or another mapping. | 3.0 |
dir() |
List the names an object has, such as attributes and methods. With no argument, list the names in the current scope. | 3.0 |
divmod() |
Divide two numbers and return the quotient and the remainder together as a tuple: (a // b, a % b). | 3.0 |
enumerate() |
Loop over an iterable and get each item together with its index, as (index, item) pairs. The start number is configurable. | 3.0 |
eval() |
Evaluate a single Python expression from a string and return its value. Dangerous with untrusted input. | 3.0 |
exec() |
Execute Python statements from a string or code object. Returns None; like eval(), never use it on untrusted input. | 3.0 |
filter() |
Keep only the items of an iterable for which a function returns True. Returns a lazy iterator, not a list. | 3.0 |
float() |
Convert a number or numeric string to a floating-point number. Also understands 'inf', '-inf' and 'nan'. | 3.0 |
format() |
Format a single value with a format spec, such as format(3.14159, '.2f') giving '3.14'. The same mini-language as f-strings. | 3.0 |
frozendict() |
Create an immutable, hashable dictionary (new in Python 3.15). It can be a dict key or set member and can't be changed. | 3.15 |
frozenset() |
Create an immutable set: unique items that can't be added or removed, so it is hashable and can be a dict key. | 3.0 |
getattr() |
Get an attribute by name, given as a string. An optional default is returned instead of raising AttributeError. | 3.0 |
globals() |
Return the dictionary of the current module's global names: variables, functions, classes and imports. | 3.0 |
hasattr() |
Return True if an object has an attribute with the given name. It works by calling getattr() and catching AttributeError. | 3.0 |
hash() |
Return the hash value of an object: an integer used by dicts and sets to find keys quickly. Only immutable values are hashable. | 3.0 |
help() |
Show the built-in help for a function, class, module or keyword: its signature and documentation. Mostly used in the REPL. | 3.0 |
hex() |
Convert an integer to a lowercase hexadecimal string prefixed with 0x, such as hex(255) giving '0xff'. | 3.0 |
id() |
Return an object's identity: a unique integer for the object while it exists. In CPython it is the memory address. | 3.0 |
input() |
Read a line of text typed by the user, after printing an optional prompt. The result is always a string. | 3.0 |
int() |
Convert a number or string to an integer. Floats are truncated toward zero, and strings can be in any base from 2 to 36. | 3.0 |
isinstance() |
Return True if an object is an instance of a class, one of its subclasses, or any class in a tuple or union of classes. | 3.0 |
issubclass() |
Return True if a class is a subclass of another class (or of any class in a tuple or union). A class is a subclass of itself. | 3.0 |
iter() |
Get an iterator from an iterable, or create one that calls a function until it returns a sentinel value. | 3.0 |
len() |
Return the number of items in a container: characters in a string, items in a list, keys in a dict, and so on. | 3.0 |
list() |
Create a list: an ordered, changeable sequence. Called with an iterable, it copies its items into a new list. | 3.0 |
locals() |
Return a dictionary of the local variables in the current scope. Inside a function it is a snapshot since Python 3.13. | 3.0 |
map() |
Apply a function to every item of one or more iterables and return a lazy iterator of the results. | 3.0 |
max() |
Return the largest item in an iterable, or the largest of several arguments. Supports a key function and a default. | 3.0 |
memoryview() |
Create a view of an object's binary data (bytes, bytearray, arrays) that slices and edits it without copying. | 3.0 |
min() |
Return the smallest item in an iterable, or the smallest of several arguments. Supports a key function and a default. | 3.0 |
next() |
Get the next item from an iterator. When it is exhausted, return the default if given, otherwise raise StopIteration. | 3.0 |
object() |
Return a new featureless object. object is the base class of every Python class and provides the default methods. | 3.0 |
oct() |
Convert an integer to an octal string prefixed with 0o, such as oct(8) giving '0o10'. Often used for file permissions. | 3.0 |
open() |
Open a file and return a file object for reading or writing text or bytes. Use it in a with block so it closes automatically. | 3.0 |
ord() |
Return the Unicode code point (an integer) of a single character, such as ord('A') giving 65. The inverse of chr(). | 3.0 |
pow() |
Raise a number to a power, like base ** exp. With a third argument it computes the result modulo a number efficiently. | 3.0 |
print() |
Write values to standard output (or a file), separated by spaces and followed by a newline. Both are configurable. | 3.0 |
property() |
Turn methods into a managed attribute with a getter, and optional setter and deleter. Usually written as @property. | 3.0 |
range() |
Create an immutable sequence of integers from start up to (but not including) stop, in steps. Used in for loops. | 3.0 |
repr() |
Return the developer-friendly string representation of an object, often valid Python code that recreates the value. | 3.0 |
reversed() |
Return an iterator that goes through a sequence backwards, without copying it. Works on lists, tuples, strings and ranges. | 3.0 |
round() |
Round a number to a given number of decimal places. Halfway values round to the nearest even number (banker's rounding). | 3.0 |
sentinel() |
Create a unique, named marker value (new in Python 3.15), such as MISSING, to tell 'no value given' apart from None. | 3.15 |
set() |
Create a set: an unordered collection of unique items with fast membership tests and set operations. | 3.0 |
setattr() |
Set an attribute on an object by name, given as a string. setattr(obj, 'x', 5) is the same as obj.x = 5. | 3.0 |
slice() |
Create a slice object, the thing behind a[start:stop:step]. Useful to name and reuse a slice. | 3.0 |
sorted() |
Return a new sorted list from any iterable. Supports a key function and reverse order; the original is left unchanged. | 3.0 |
staticmethod() |
Turn a method into a static method that receives neither the instance nor the class. Usually written as @staticmethod. | 3.0 |
str() |
Convert a value to its readable text form, or decode bytes into a string. Strings are immutable sequences of characters. | 3.0 |
sum() |
Add up the numbers in an iterable, plus an optional start value. Floats are summed with extra precision since Python 3.12. | 3.0 |
super() |
Return a proxy that calls methods of the parent class, so a subclass can extend a method instead of replacing it. | 3.0 |
tuple() |
Create a tuple: an ordered, immutable sequence. Tuples are hashable when their items are, so they can be dict keys. | 3.0 |
type() |
With one argument, return an object's type. With three arguments, create a new class dynamically. | 3.0 |
vars() |
Return the __dict__ of a module, class or object: its writable attributes as a dictionary. With no argument, like locals(). | 3.0 |
zip() |
Iterate over several iterables in parallel, producing tuples of their items. Stops at the shortest unless strict=True. | 3.0 |
__import__() |
The low-level function the import statement calls. Use importlib.import_module() instead to import a module by name. | 3.0 |