Built-in Functions Deep Dive
Python has 70+ built-in functions. Master the most commonly used ones: len(), type(), range(), print(), input(), int(), float(), str(), list(), dict(), sorted(), map(), filter(), zip(), enumerate(), abs(), round(), max(), min(), sum(), any(), all().
Essential Built-in Functions
# Math
print(abs(-5)) # 5
print(round(3.7)) # 4
print(round(3.14159, 2)) # 3.14
print(max(1, 5, 3)) # 5
print(min(1, 5, 3)) # 1
print(sum([1, 2, 3, 4])) # 10
print(pow(2, 8)) # 256
# Type conversion
print(int("42")) # 42
print(float("3.14")) # 3.14
print(str(100)) # "100"
print(bool(0)) # False
# Sequences
print(len("Python")) # 6
print(sorted([3, 1, 2])) # [1, 2, 3]
print(reversed([1, 2, 3]))
# zip — combine iterables
names = ["Alice", "Bob"]
ages = [25, 30]
combined = list(zip(names, ages))
print(combined) # [('Alice', 25), ('Bob', 30)]
# any() and all()
nums = [1, 2, 0, 4]
print(any(nums)) # True (at least one truthy)
print(all(nums)) # False (0 is falsy)
# isinstance — check type
print(isinstance(42, int)) # True
print(isinstance("hi", str)) # True
print(isinstance(3.14, (int, float))) # TrueTip
Tip
Use isinstance() instead of type() for type checking: isinstance(42, (int, float)) handles inheritance. Use zip() to iterate over multiple lists in parallel.
Everything in Python is an object — use type() to check
Common Mistake
Warning
all([]) returns True (vacuous truth). An empty list has no False elements. Check length first if needed: if items and all(items).
Practice Task
Note
(1) Use zip to combine names and scores. (2) Use any() to check if any score > 90. (3) Use sorted with key=len. (4) Use isinstance to check types.