Python Built-in Functions
Every Python built-in function that matters — the real signature, real examples that actually run, and the gotcha for each one. Python 3.10+ semantics (no Python 2 baggage).
Iteration
enumerate()
Yields (index, item) tuples from an iterable. Preferred over manual index counters in for-loops.
zip()
Pairs elements from multiple iterables into tuples, stopping at the shortest. With strict=True, raises ValueError if lengths differ.
range()
Returns an immutable range object representing an arithmetic sequence of integers. Memory-efficient — values are computed lazily, not stored.
map()
Applies a function to each item of one or more iterables, yielding results lazily. Returns a map object (iterator), not a list.
filter()
Yields items from iterable for which function(item) is truthy. If function is None, filters out falsy items.
Transformation
sorted()
Returns a new sorted list from any iterable. Uses Timsort — stable, O(n log n).
sum()
Sums the items of an iterable, adding them to start. Optimized for numbers.
min()
Returns the smallest item in an iterable or the smallest of two or more arguments. Supports a key function for custom comparison.
max()
Returns the largest item in an iterable or the largest of two or more arguments. Supports a key function for custom comparison.
any()
Returns True if any element of the iterable is truthy. Short-circuits on the first truthy value.
all()
Returns True if every element of the iterable is truthy (or if the iterable is empty). Short-circuits on the first falsy value.
Inspection
len()
Returns the number of items in a container. Calls the object's __len__ method.
type()
Returns the type of an object, or dynamically creates a new type when called with three arguments. type(x) is the runtime class of x.
isinstance()
Returns True if the object is an instance of classinfo (a class or tuple of classes). Respects the class hierarchy — subclasses count.
hasattr()
Returns True if the object has an attribute with the given name. Implemented by calling getattr() and catching AttributeError.
getattr()
Returns the value of the named attribute of object. If the attribute is missing, returns default (if given) or raises AttributeError.
Input / Output
print()
Writes the given objects to a text stream, converting each with str() and joining with sep. Adds end (newline by default) after the last object.
input()
Reads a line from sys.stdin, strips the trailing newline, and returns it as a string. Optionally writes prompt to stdout first.
open()
Opens a file and returns a file object. Default mode 'r' is text read; use 'rb'/'wb' for binary.
Type Conversion
int()
Constructs an integer from a number or string. When x is a string, base selects the numeric base (0 auto-detects from prefix).
float()
Constructs a floating-point number from a number or string. Accepts 'inf', '-inf', 'nan' (case-insensitive).
str()
Returns a str version of an object. With bytes/bytearray, decodes using encoding.
dict()
Constructs a dictionary from keyword args, another mapping, or an iterable of key/value pairs. Insertion order is preserved (Python 3.7+).