All References

Python Built-in Functions

Complete reference for Python's 69 built-in functions organized by category, with signatures, descriptions, and examples.

Type Conversion

Function Signature Description & Example
int() int(x=0, base=10) Convert to integer. int("42") → 42, int("0xFF", 16) → 255
float() float(x=0.0) Convert to float. float("3.14") → 3.14, float("inf") → inf
str() str(object='') Convert to string. str(42) → "42", str([1,2]) → "[1, 2]"
bool() bool(x=False) Convert to boolean using truthiness rules. bool(0) → False, bool("hi") → True
bytes() bytes(source, encoding, errors) Immutable byte sequence. bytes("hi", "utf-8") → b'hi'
bytearray() bytearray(source, encoding) Mutable byte array; same args as bytes()
complex() complex(real=0, imag=0) Create complex number. complex(2, 3) → (2+3j)
list() list(iterable=()) Create list from iterable. list("abc") → ['a','b','c']
tuple() tuple(iterable=()) Immutable sequence. tuple([1,2,3]) → (1, 2, 3)
set() set(iterable=()) Mutable unordered unique collection. set([1,2,2]) → {1,2}
frozenset() frozenset(iterable=()) Immutable set; hashable, can be dict key
dict() dict(**kwargs) Create dict. dict(a=1, b=2) → {"a":1,"b":2}

Math & Numbers

Function Signature Description & Example
abs() abs(x) Absolute value. abs(-5) → 5, abs(3+4j) → 5.0
divmod() divmod(a, b) Returns (quotient, remainder). divmod(17, 5) → (3, 2)
max() max(iterable, *, key, default) Largest item. max([3,1,4]) → 4, max("abc") → 'c'
min() min(iterable, *, key, default) Smallest item. min([3,1,4]) → 1
pow() pow(base, exp, mod=None) Raise to power. pow(2, 10) → 1024; 3-arg form: pow(2,10,100) → 24
round() round(number, ndigits=None) Round to n digits. round(3.14159, 2) → 3.14. Uses banker's rounding.
sum() sum(iterable, /, start=0) Sum of iterable. sum([1,2,3]) → 6, sum([1,2], 10) → 13

Iteration & Sequences

Function Signature Description & Example
enumerate() enumerate(iterable, start=0) Yields (index, value) pairs. for i, v in enumerate(['a','b'])
filter() filter(function, iterable) Returns items where function returns True. list(filter(None, [0,1,2])) → [1,2]
map() map(function, *iterables) Apply function to each item. list(map(str, [1,2,3])) → ['1','2','3']
zip() zip(*iterables, strict=False) Pairs elements from each iterable. list(zip([1,2],[3,4])) → [(1,3),(2,4)]
range() range(stop) / range(start, stop, step) Lazy integer sequence. range(0,10,2) → 0,2,4,6,8
reversed() reversed(sequence) Reverse iterator. list(reversed([1,2,3])) → [3,2,1]
sorted() sorted(iterable, *, key, reverse=False) Returns new sorted list. sorted([3,1,2]) → [1,2,3]
len() len(obj) Number of items. len("hello") → 5, len([1,2,3]) → 3
iter() iter(object, sentinel) Get iterator from object. 2-arg form calls object until sentinel is returned.
next() next(iterator, default) Retrieve next item from iterator. Returns default if exhausted (instead of StopIteration).
slice() slice(stop) / slice(start, stop, step) Create a slice object. Used when building custom sequence types.

Object & Class

Function Signature Description & Example
type() type(obj) / type(name, bases, dict) Return type or dynamically create a new class. type(42) → <class 'int'>
isinstance() isinstance(obj, classinfo) Check instance. isinstance(42, int) → True; accepts tuple of types.
issubclass() issubclass(cls, classinfo) Check class hierarchy. issubclass(bool, int) → True
id() id(obj) Return object identity (memory address in CPython). Unique per object lifetime.
hash() hash(obj) Integer hash value for use in sets/dicts. Only hashable (immutable) objects supported.
getattr() getattr(obj, name, default) Get attribute by string name. getattr(obj, 'x', 0) returns 0 if x not found.
setattr() setattr(obj, name, value) Set attribute by string name. Equivalent to obj.name = value.
delattr() delattr(obj, name) Delete attribute. Equivalent to del obj.name.
hasattr() hasattr(obj, name) True if attribute exists. Internally calls getattr and checks for AttributeError.
callable() callable(obj) True if object has a __call__ method. callable(print) → True
dir() dir(obj) List of attribute names. Without argument, returns names in current scope.
vars() vars(obj) Return __dict__ of object. Without argument, equivalent to locals().

I/O & Formatting

Function Signature Description
print() print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) Write to stdout. Customize separator and ending character.
input() input(prompt='') Read a string from stdin. Always returns a string — cast if needed.
open() open(file, mode='r', encoding=None, ...) Open a file. Modes: r, w, a, b, +. Use as context manager: with open(...) as f:
format() format(value, format_spec='') Format a single value. format(3.14159, '.2f') → '3.14', format(255, 'x') → 'ff'

Introspection, Numeric Repr & Execution

Function Signature Description & Example
repr() repr(obj) Developer-friendly string. repr("hi") → "'hi'"
hex() hex(x) Hex string. hex(255) → '0xff'
oct() oct(x) Octal string. oct(8) → '0o10'
bin() bin(x) Binary string. bin(10) → '0b1010'
chr() chr(i) Unicode char from code point. chr(65) → 'A', chr(128512) → '😀'
ord() ord(c) Unicode code point of a single char. ord('A') → 65
all() all(iterable) True if all elements are truthy (or iterable is empty). all([1,2,3]) → True
any() any(iterable) True if any element is truthy. any([0, 0, 1]) → True
eval() eval(expression, globals, locals) Evaluate a Python expression string. Dangerous with untrusted input.
exec() exec(object, globals, locals) Execute Python code string or code object. Returns None. Avoid with untrusted input.
globals() globals() Return current global symbol table as a dict.
locals() locals() Return current local symbol table. Modifications may not affect actual locals.
super() super(type, obj) Proxy to parent class. super().__init__() in subclasses to call parent constructor.
property() property(fget, fset, fdel, doc) Create managed attribute. Typically used as @property decorator.
staticmethod() staticmethod(function) Decorator to create a method with no implicit first argument (no self/cls).
classmethod() classmethod(function) Method receives the class as the first argument (cls). Used for factory methods.

Frequently Asked Questions

What is the difference between list() and []?

[] is a list literal — the fastest way to create an empty list or a list with literal items. list() is a constructor that accepts any iterable and converts it to a list. Use [] when you want an empty list or know the items; use list() when converting another iterable (e.g., a generator, set, or string) to a list.

How does enumerate() work in Python?

enumerate(iterable, start=0) wraps an iterable and yields (index, value) tuples. Instead of for i in range(len(lst)): v = lst[i], write for i, v in enumerate(lst):. The start parameter lets you begin counting from any number.

What does zip() do in Python?

zip(*iterables) aggregates elements from multiple iterables into tuples. zip([1,2,3], ['a','b','c']) yields (1,'a'), (2,'b'), (3,'c'). By default it stops at the shortest iterable. In Python 3.10+, strict=True raises an error if lengths differ. To unzip, use zip(*zipped).