Python builtins Module
Example
Use a few common built-in functions:
# Names: Emil, Tobias, Linus
print(len(["Emil", "Tobias"]))
print(sum([1, 2, 3]))
Try it Yourself »
Definition and Usage
The builtins module provides direct access to all built-in identifiers of Python.
Use it to reference built-in functions, exceptions, and constants explicitly, or to inspect/override built-ins.
Members
Member | Description |
---|---|
abs() | Return the absolute value of a number. |
all() | Return True if all elements of the iterable are true. |
any() | Return True if any element of the iterable is true. |
ascii() | Return a readable string of an object with non-ASCII characters escaped. |
bin() | Convert an integer to a binary string prefixed with 0b . |
bool() | Return a Boolean value. |
bytearray() | Create a mutable sequence of bytes. |
bytes() | Create an immutable sequence of bytes. |
callable() | Return True if the object appears callable. |
chr() | Return the string representing a character for the given Unicode code point. |
classmethod() | Return a method that receives the class as the first argument (cls ); used as a decorator for defining class methods. |
dict() | Create a new dictionary. |
dir() | Return a list of names in the current scope or attributes of an object. |
divmod() | Return the pair (quotient, remainder) of dividing two numbers. |
enumerate() | Return an enumerate object. |
eval() | Evaluate a string as a Python expression and return the result. |
exec() | Execute Python code dynamically. |
filter() | Construct an iterator from elements of iterable for which function returns true. |
float() | Construct a floating point number. |
format() | Return a formatted string using the given format spec. |
frozenset() | Create an immutable set. |
getattr() | Return the value of the named attribute of an object; fallback if missing. |
globals() | Return a dict of the current global symbol table. |
hasattr() | Return True if an object has the named attribute. |
hash() | Return the hash value of the object (if it has one). |
help() | Invoke the built-in help system. |
hex() | Convert an integer to a hexadecimal string prefixed with 0x . |
id() | Return the identity (memory address) of an object. |
input() | Read a line from input, returning it as a string. |
int() | Construct an integer number. |
isinstance() | Return True if an object is an instance of a class or tuple of classes. |
issubclass() | Return True if a class is a subclass of another class or tuple of classes. |
iter() | Return an iterator from an object. |
len() | Return the number of items in a container. |
list() | Create a new list. |
map() | Return an iterator that applies function to every item of iterable. |
max() | Return the largest item in an iterable or the largest of two or more arguments. |
memoryview() | Create a memory view object of the given bytes-like object. |
min() | Return the smallest item in an iterable or the smallest of two or more arguments. |
next() | Retrieve the next item from an iterator; default if exhausted. |
oct() | Convert an integer to an octal string prefixed with 0o . |
open() | Open file and return a corresponding file object. |
ord() | Return the Unicode code point of a one-character string. |
pow() | Return base raised to power; with three args, compute modular exponentiation. |
print() | Print objects to text stream file. |
property() | Return a property attribute; used as a decorator to define managed attributes (with optional getter/setter/deleter). |
range() | Return an immutable sequence of numbers. |
repr() | Return a string with a printable representation of an object. |
reversed() | Return a reverse iterator over a sequence. |
round() | Round a number to a given precision in decimal digits. |
set() | Create a new set object. |
slice() | Create a slice object to specify how to slice a sequence. |
sorted() | Return a new sorted list from the items in iterable. |
staticmethod() | Return a static method; used as a decorator to define methods that do not receive an implicit first argument. |
str() | Return a string version of object. |
sum() | Sum items of an iterable. |
super() | Return a proxy object that delegates method calls to a parent or sibling class. |
tuple() | Create a new tuple. |
type() | Return the type of an object; can also create new types. |
vars() | Return the __dict__ attribute for a module, class, instance, or the current locals. |
zip() | Return an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument iterables. |