Built-in functions are the functions Python makes available everywhere, with no import: print(), len(), sum(), sorted(), zip() and about seventy others. Knowing the common ones well replaces many hand-written loops with a single clear call:
orders = [4, 7, 2]
print(len(orders), sum(orders), max(orders)) # 3 13 7
print(sorted(orders, reverse=True)) # [7, 4, 2]This reference groups the most useful built-ins by job: inspecting values, aggregating them, transforming sequences and constructing collections. Each group notes the edge cases that trip people up, such as max() on an empty list and zip() on lists of different lengths. The examples summarise orders at a seed shop.
Inspection
These functions tell you what a value is or what it contains:
| Function | Returns |
|---|---|
type(x) | the exact class of x |
isinstance(x, T) | True if x is a T or a subclass of T |
len(x) | number of items in a sized object |
id(x) | a unique identity number for the object |
dir(x) | names of attributes and methods |
help(x) | the documentation for x |
callable(x) | whether x can be called like a function |
For type checks in real code, prefer isinstance() to type(x) == T. isinstance(True, int) is True because bool subclasses int, and isinstance(value, (int, float)) accepts several types at once. type(x) == int would reject subclasses that should be acceptable.
dir() and help() are exploration tools for the interactive shell: help(str.split) shows a method's parameters without opening a browser.
Aggregation
Aggregation functions reduce a collection to one answer:
quantities = [4, 7, 2]
print(sum(quantities), min(quantities), max(quantities)) # 13 2 7
print(all(q > 0 for q in quantities)) # True: every one positive
print(any(q > 5 for q in quantities)) # True: at least one above 5
print(round(sum(quantities) / len(quantities), 2)) # 4.33min()andmax()acceptkey=to compare by something else:max(products, key=len)finds the longest name.- On an empty sequence,
min()andmax()raiseValueError. Passdefault=to return a value instead:max(quantities, default=0). sum()starts from 0;sum(prices, start=10)starts from 10. Usemath.fsum()for accurate sums of many floats.all([])isTrueandany([])isFalse, which follows logic ("no counter-examples") but surprises many people.
any() and all() stop as soon as the answer is known, so they're efficient with generator expressions.
Transformation
These built-ins produce a new view or ordering of existing data:
| Function | What it does |
|---|---|
sorted(it, key=, reverse=) | new sorted list |
reversed(seq) | iterator going backwards |
enumerate(it, start=0) | pairs of (position, item) |
zip(a, b, ...) | tuples of items at the same position |
map(func, it) | apply a function to every item |
filter(func, it) | keep items where the function is truthy |
names = ["kale", "bean", "squash"]
counts = [4, 7]
print(list(zip(names, counts))) # [('kale', 4), ('bean', 7)]
print(list(zip(names, counts, strict=False))) # same: extra 'squash' ignoredzip() stops at the shortest input, silently dropping extras. From Python 3.10, zip(..., strict=True) raises ValueError when the lengths differ, which catches mismatched data. itertools.zip_longest() fills the gaps instead. reversed, enumerate, zip, map and filter return lazy iterators; wrap them in list() to see or reuse the results.
Construction
Calling a type creates a value of that type:
items = ["kale", "bean", "kale"]
print(list("abc")) # ['a', 'b', 'c']
print(set(items)) # {'kale', 'bean'} (order may vary)
print(dict(zip(["kale", "bean"], [4, 7]))) # {'kale': 4, 'bean': 7}
print(tuple(range(3))) # (0, 1, 2)list(), tuple(), set() and dict() build collections from any iterable; int(), float(), str() and bool() convert single values, as covered in type casting.
Construction consumes iterators: list(some_generator) reads every remaining value, leaving the generator empty, and stores them all in memory. That's what you want when you need to reuse or index the data, and a mistake when the input is huge or endless. Two built-ins should almost never be used on outside data: eval() and exec() run arbitrary code, so a malicious string can do anything your program can. Use int(), float(), json.loads() or ast.literal_eval() to parse text instead.
Independent practice and a worked check
Task: build a seed order summary using inspection, aggregation and paired traversal without eval or exec.
names = ["kale", "bean", "pea"]
raw_counts = ["4", "7", "x"]
counts = []
for name, raw in zip(names, raw_counts, strict=True):
if raw.isdigit():
counts.append((name, int(raw)))
else:
print(f"Skipping {name}: {raw!r} is not a count")
print(counts)
print("Types ok:", all(isinstance(c, int) for _, c in counts))
print("Total:", sum(c for _, c in counts), "Largest:", max(counts, key=lambda p: p[1])[0])This prints the skip message for "pea", then [('kale', 4), ('bean', 7)], Types ok: True and Total: 11 Largest: bean. For the worked check, ordinary zip() with unequal lengths stops at the shortest iterable.
Reference and next practice
The documentation lists all built-in functions with their parameters. Continue with the methods reference and the standard library tour. Practise with the Python exercises and Python quiz.
Built-in Functions Reference Summary
- Inspection: type, isinstance, len and callable answer different questions about an object.
- Aggregation: sum, min, max, any and all summarize collections using different rules.
- Transformation: sorted, reversed, enumerate and zip provide useful traversal transformations.
- Construction: list, tuple, set and dict construct collections while int, float and str construct common scalar values.
Built-in Functions Reference Examples
Each example shows the code, the output it produces and what each part does.
Built-in Functions Reference in a small program
orders = [4, 7, 2]
print(sum(orders), min(orders), max(orders))
print(all(quantity > 0 for quantity in orders))
print(list(enumerate(orders, start=1)))13 2 7
True
[(1, 4), (2, 7), (3, 2)]Line-by-line explanation
- Line 2Three aggregations in one line: total, smallest and largest.
- Line 3
all()with a generator checks every quantity is positive. - Line 4
enumerate(..., start=1)numbers the orders from 1;list()shows the pairs.
A seed order summary
seeds = ["kale", "bean", "squash", "pea"]
quantities = [4, 7, 0, 3]
prices = [2.5, 1.75, 3.0, 1.2]
lines = [(s, q, p) for s, q, p in zip(seeds, quantities, prices, strict=True) if q > 0]
for number, (seed, qty, price) in enumerate(lines, start=1):
print(f"{number}. {seed:<7} x{qty} £{qty * price:.2f}")
total = sum(q * p for _, q, p in lines)
print(f"Total: £{total:.2f}")
print("Biggest line:", max(lines, key=lambda line: line[1] * line[2])[0])
print("All in stock:", all(q > 0 for q in quantities))
print("Cheapest seed:", min(zip(prices, seeds))[1])
print("Empty max:", max([], default="none"))1. kale x4 £10.00
2. bean x7 £12.25
3. pea x3 £3.60
Total: £25.85
Biggest line: bean
All in stock: False
Cheapest seed: pea
Empty max: noneLine-by-line explanation
- Line 5
strict=True(Python 3.10+) would raise an error if one list were shorter. - Line 11
key=makesmax()compare line totals while returning the whole tuple. - Line 13Tuples compare by their first item, so
min()on (price, seed) pairs finds the cheapest. - Line 14
default=avoidsValueErroron an empty sequence.
Common Built-in Functions Reference Mistakes
Calling max() on data that might be empty
orders = []
largest = max(orders) # ValueError: max() arg is an empty sequenceorders = []
largest = max(orders, default=0)Losing data silently with zip()
names = ["kale", "bean", "squash"]
counts = [4, 7]
stock = dict(zip(names, counts)) # squash quietly disappearsstock = dict(zip(names, counts, strict=True)) # ValueError points at the mismatchBuilt-in Functions Reference in Real Projects
Built-ins in professional code
Experienced Python developers reach for built-ins before writing loops: sum() for totals, any() to check whether a list contains a problem, sorted(..., key=...) to rank search results, zip() to pair columns, and enumerate() for numbered output. Code that uses them is shorter, harder to get wrong and usually faster, because built-ins run in optimised C.
Linters such as Ruff suggest built-in replacements for common loop patterns, and flag eval() on input as a security issue. The full list of built-ins is short enough to read in one sitting, and doing so is one of the most efficient ways to improve your Python.
Built-in Functions Reference FAQ
How many built-in functions does Python have?
Around 70 in current Python 3 versions, listed on the "Built-in Functions" page of the documentation. You'll use perhaps twenty of them regularly: print, len, range, type, isinstance, int, str, list, dict, sum, min, max, sorted, enumerate, zip, any, all, open, input and round.
What is the difference between sorted() and list.sort()?
sorted(iterable) works on any iterable and returns a new list, leaving the original unchanged. list.sort() only works on lists, sorts in place and returns None. Both accept key= and reverse=.
Should I use map() and filter() or comprehensions?
Comprehensions are usually more readable and are the common Python style. map() is neat when you already have a named function, as in list(map(int, parts)). Both produce the same results.
Why is using eval() dangerous?
eval() runs any Python expression in the string, so text from a user, file or network could delete files or steal data. Use specific parsers instead: int(), float(), json.loads(), or ast.literal_eval() for Python literal syntax.
Can I overwrite a built-in function name?
Yes, by assigning to it, for example list = [1, 2]. Python allows it, but the built-in is then hidden in that scope and later calls such as list(range(3)) fail with TypeError: 'list' object is not callable. Choose different names.
Built-in Functions Reference Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
What does ordinary zip do with unequal iterable lengths?
Which review concern is valid for built-in functions reference?
Built-in Functions Reference Quiz
2 questions to check what you learned.
What does ordinary zip do with unequal iterable lengths?
- Fill missing values automatically
- Stop at the shortest
- Python ignores the distinction
Which statement correctly describes transformation?
- sorted, reversed, enumerate and zip provide useful traversal transformations.
- Only the example output matters, not the rule
- Every operation has the same behavior