Definition
Built-in functions are always available in Python, with no import needed. They cover maths (abs, sum, max), type conversion (int, str, list), inspecting things (type, isinstance, dir), and working with iterables (len, sorted, enumerate, zip, any, all).
In simple words
They're the tools already on your desk before you open any toolbox. Knowing them saves you from writing code that Python has already written.
Why it matters
They're fast, they're clear, and everyone recognises them. They come up in nearly every coding interview too.
How it works
| Group | Functions |
|---|---|
| Maths | abs, sum, min, max, round, pow, divmod |
| Types | int, float, str, bool, list, tuple, set, dict |
| Inspect | type, isinstance, len, dir, help, id |
| Iterables | range, enumerate, zip, map, filter, sorted, reversed, any, all, iter, next |
| Input and output | print, input, open |
| Characters | ord, chr, bin, hex |
In code
marks = [40, 75, 90, 62]
print(sum(marks), max(marks), min(marks), round(sum(marks) / len(marks), 1))
print(sorted(marks, reverse=True))
print(any(m < 50 for m in marks), all(m > 30 for m in marks))
print(divmod(17, 5))
print(isinstance(marks, list), type(marks).__name__)
print(max(["pen", "notebook"], key=len))
print(bin(5), hex(255), ord("A"), chr(66))Output
267 90 40 66.8 [90, 75, 62, 40] True True (3, 2) True list notebook 0b101 0xff 65 B
Common mistakes
- Naming a variable list, max or sum. It hides the built-in for the rest of your code.
- Using type(x) == int where isinstance(x, int) is better, as it also accepts subclasses.
Check yourself
Summary
- Built-ins are always available.
- Don't reuse their names for variables.
Finished reading?
Sources: Python docs: Built-in Functions