Built-in Functions
Master essential built-in Python functions. Read the lesson first, then move through the exercises in order.
After reading
Practice Arena
Begin with the first exercise, then continue step by step through the module.
Start with Data Range NormalizationStudy Material
Read the full lesson
Why built-in functions matter
Built-in functions come with Python and are always available. They are tested, fast, and save you from rewriting common logic.
A simple mental model
Think of a function as input going in and output coming out. You can store the output or pass it into another function.
pythonlength = len("python") print(length)
len() for size and count
Use len() for strings, lists, tuples, dictionaries, and more. For dictionaries, it counts keys.
pythonprint(len("python")) print(len([1, 2, 3])) print(len({"a": 1, "b": 2}))
min() and max() for comparisons
They work on numbers, strings, and other ordered data. You can also provide a key function to control what is compared.
pythonvalues = [3, 7, 2, 9] print(min(values)) print(max(values)) words = ["pear", "banana", "fig"] print(min(words, key=len)) # shortest word
sum() for totals
sum() adds numbers in a sequence. Use start if you want to add an initial value.
pythonprices = [4.5, 2.0, 3.25] print(sum(prices)) print(sum(prices, 10)) # start at 10
If you are summing strings, convert them to numbers first.
abs() and round()
abs() removes the sign. round() controls decimal places.
pythonprint(abs(-12)) print(round(3.14159, 2)) print(round(2.5))
sorted() and key
sorted() returns a new list and leaves the original unchanged. Use key and reverse to control the order.
pythonnames = ["bob", "Alice", "carol"] print(sorted(names)) print(sorted(names, key=str.lower)) pairs = [("a", 3), ("b", 1), ("c", 2)] print(sorted(pairs, key=lambda p: p[1]))
any() and all()
These return True or False based on a list of conditions.
pythonprint(any([False, False, True])) # True print(all([True, True, False])) # False
any() is True if at least one item is True. all() is True only if all items are True.
isinstance() for safe type checks
Use isinstance() when you need to confirm a value type.
pythonvalue = "42" print(isinstance(value, str)) print(isinstance(value, (int, float)))
Simple type conversions
int(), float(), and str() turn values into common types.
pythonprint(int("42")) print(float("3.14")) print(str(123)) print(int("101", 2)) # base 2
Common mistakes to avoid
- Forgetting that
sorted()returns a new list. - Passing strings to
sum()without converting to numbers. - Using
type(x) == ...instead ofisinstance().
What you should understand after this lesson
- Why built-ins are reliable and worth using.
- How to use len, min, max, sum, abs, round, and sorted.
- How any() and all() summarize conditions.
- How to do safe type checks and conversions.
Interactive
Exercises for this topic
These exercises follow the exact order of the lesson. Move step-by-step from reading into coding.
Data Range Normalization
Use min(), max() and round() to process an analytical calculation.
Custom Sort Logic
Use sorted() with a functional key to manipulate lists intelligently.
Batch Validation
Use any() and all() to evaluate system state rules.
Data Type Filtering
Filter mixed list elements using isinstance() to safeguard processes.
Absolute Summation
Chain multiple built-in functions seamlessly.