Python Built-in Functions Reference
This reference lists Python's built‑in functions, providing concise English descriptions and example code snippets for each, covering topics from basic type conversions and arithmetic to object introspection and file handling and utility operations.
This article provides an English reference of Python's built‑in functions, including a brief description and example usage for each function.
Function Name
Description
Usage
abs(x)
Returns the absolute value of a number.
abs(-10)→
10all(iterable)
Checks whether all elements in the iterable are true.
all([True, False, 1])→
Falseany(iterable)
Checks whether any element in the iterable is true.
any([False, False, True])→
Trueascii(object)
Returns an ASCII‑only representation of the object.
ascii('hello')→
'hello'bin(x)
Converts an integer to its binary string representation.
bin(10)→
'0b1010'bool(x)
Converts the object to a Boolean value.
bool(0)→
Falsechr(i)
Returns the Unicode character corresponding to the integer.
chr(65)→
'A'dict(**kwargs / seq)
Creates a dictionary.
dict(one=1, two=2)or
dict([('one', 1), ('two', 2)])dir(obj)
Lists all attributes and methods of the object.
dir(str)divmod(a, b)
Returns a tuple of the quotient and remainder.
divmod(10, 3)→
(3, 1)enumerate(iterable, start=0)
Returns an enumerate object yielding pairs of index and value.
list(enumerate(['a', 'b', 'c']))→
[(0, 'a'), (1, 'b'), (2, 'c')]eval(expression[, globals[, locals]])
Evaluates the given expression string.
eval("2+2")→
4filter(function, iterable)
Filters elements for which the function returns true.
list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4]))→
[2, 4]float(x)
Converts a number or string to a floating‑point number.
float("3.14")→
3.14format(value[, format_spec])
Formats a value using a format string.
'{} {}'.format('Hello', 'World')→
'Hello World'frozenset(iterable)
Creates an immutable set.
frozenset([1, 2, 3])hash(object)
Returns the hash value of the object.
hash('hello')hex(x)
Converts an integer to a lowercase hexadecimal string.
hex(255)→
'0xff'id(object)
Returns the unique identifier of the object.
id([])input([prompt])
Reads a line from input, optionally displaying a prompt.
input("Enter your name: ")int(x[, base])
Converts a number or string to an integer.
int("123", 10)→
123len(s)
Returns the length of the object.
len("hello")→
5list(iterable)
Converts an iterable to a list.
list(range(5))→
[0, 1, 2, 3, 4]map(function, iterable, ...)
Applies a function to each element of the iterable.
list(map(lambda x: x**2, [1, 2, 3]))→
[1, 4, 9]max(*args[, key, default])
Returns the largest of the arguments.
max(1, 2, 3)→
3min(*args[, key, default])
Returns the smallest of the arguments.
min(1, 2, 3)→
1next(iterator[, default])
Returns the next item from the iterator.
next(iter([1, 2, 3]))→
1open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
Opens a file and returns a file object.
f = open("file.txt", "w")pow(base, exp[, mod])
Returns base raised to the power exp (modulo mod if provided).
pow(2, 3)→
8print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Prints objects to the console.
print("Hello", "World")range(stop) / range(start, stop[, step])
Creates an immutable sequence of integers.
for i in range(5): print(i)Function Name
Description
Usage
reversed(seq)
Returns a reversed iterator.
for i in reversed('abc'): print(i)round(number[, ndigits])
Rounds a number to a given precision.
round(3.14159, 2)→
3.14set(iterable)
Creates an unordered collection of unique elements.
set([1, 2, 2, 3, 4, 4])→
{1, 2, 3, 4}slice(start, stop[, step])
Creates a slice object.
range(10)[slice(2, 7, 2)]sorted(iterable[, key, reverse])
Returns a new sorted list from the iterable.
sorted([3, 1, 4, 1, 5, 9, 2])→
[1, 1, 2, 3, 4, 5, 9]str(object='')
Converts an object to its string representation.
str(123)→
'123'sum(iterable[, start])
Returns the sum of a sequence of numbers.
sum([1, 2, 3, 4, 5])→
15tuple(iterable)
Converts an iterable to a tuple.
tuple('abc')→
('a', 'b', 'c')type(object) / type(name, bases, dict)
Returns the type of an object or creates a new type.
type('hello')/
MyClass = type('MyClass', (object,), {'attr': 'value'})vars([object])
Returns the __dict__ attribute of an object, or locals if no argument.
class A: pass; a = A(); vars(a)zip(*iterables)
Aggregates elements from each iterable into tuples.
list(zip('ABCD', 'xy'))→
[('A', 'x'), ('B', 'y')]import(name[, globals[, locals[, fromlist[, level]]]])
Dynamically imports a module.
module = __import__('sys')Function Name
Description
Usage
compile(source, filename, mode[, flags[, dont_inherit]])
Compiles Python source code into a code object.
compile('print("Hello, World!")', '<string>', 'exec')complex(real[, imag])
Creates a complex number.
complex(1, 2)→
(1+2j)delattr(object, name)
Deletes an attribute from an object.
class C: x = 1; c = C(); delattr(c, 'x')dir([object])
Without arguments, returns names in the current scope; with an object, returns its attributes.
dir()/
dir(list)exec(object[, globals[, locals]])
Executes a compiled code object or a string of Python code.
exec('print("Hello, World!")')globals()
Returns a dictionary representing the current global symbol table.
globals()['__name__']hasattr(object, name)
Checks whether an object has a given attribute.
hasattr(int, '__add__')help([object])
Invokes the built‑in help system for the object, or the interactive help if no object is given.
help(print)hex(x)
Converts an integer to a lowercase hexadecimal string.
hex(255)→
'0xff'input([prompt])
Reads a line from input, optionally displaying a prompt.
input('Please enter your name: ')isinstance(object, classinfo)
Checks if the object is an instance of a class or a tuple of classes.
isinstance('test', str)issubclass(class, classinfo)
Checks if a class is a subclass of another class or a tuple of classes.
issubclass(int, object)iter(o[, sentinel])
Returns an iterator for the object; sentinel can be used for special termination.
iter(range(5), 3)locals()
Returns a dictionary representing the current local symbol table.
Called inside a function:
locals()Function Name
Description
Usage
oct(x)
Converts an integer to an octal string.
oct(123)→
'0o173'ord(c)
Returns the Unicode code point for a single character.
ord('A')→
65pow(base, exponent[, modulo])
Computes exponentiation, optionally modulo.
pow(2, 3, 5)→
3property(fget=None, fset=None, fdel=None, doc=None)
Creates a property attribute with optional getter, setter, deleter, and docstring.
class C: ... @property
def value(self): return self._valuerepr(object)
Returns a string containing a printable representation of an object.
repr(123)→
'123'setattr(object, name, value)
Sets the value of an attribute on an object.
class C: pass; c = C(); setattr(c, 'x', 10)slice(stop) / slice(start, stop[, step])
Creates a slice object.
s = slice(1, 5); my_list[s]staticmethod(function)
Converts a function into a static method.
class C: @staticmethod
def method(): passsuper(type[, object-or-type])
Provides a proxy object to delegate method calls to a parent class.
class B(A):
def method(self):
super().method()zip(*iterables)
Aggregates elements from each iterable into tuples.
list(zip('ABCD', 'xy'))→
[('A', 'x'), ('B', 'y')]Function Name
Description
Usage
import(name[, globals[, locals[, fromlist[, level]]]])
Dynamic module import.
math = __import__('math')callable(object)
Checks if the object appears callable.
callable(abs)→
Truecompile(source, filename, mode[, flags[, dont_inherit]])
Compiles source code into a code object.
code_obj = compile("print('Hello, world!')", "<string>", "exec")delattr(object, name)
Deletes an attribute from an object.
class C: x = 1; c = C(); delattr(c, 'x')format(value[, format_spec])
Formats a value using a format specification.
format(3.14159, '.2f')→
'3.14'globals()
Returns the dictionary of the current global symbol table.
globals()['__name__']hasattr(object, name)
Checks if an object has a given attribute.
hasattr(int, '__add__')help([object])
Shows help information for the object or the interactive help system.
help(print)intern(string)
Interns a string, improving memory efficiency for many identical strings.
intern('example_string')memoryview(obj)
Creates a memory‑view object that exposes the buffer interface of the given object.
m = memoryview(b'ABCDEF')open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
Opens a file and returns a file object.
f = open("file.txt", "w")property([fget[, fset[, fdel[, doc]]]])
Defines a property with optional getter, setter, deleter, and docstring.
See earlier examples.
vars([object])
Returns the __dict__ of an object, or locals if no argument is given.
class C: x = 1; c = C(); vars(c)Test Development Learning Exchange
Test Development Learning Exchange
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.