Python comes with a rich set of built-in functions that are always available—no imports required. These functions cover everything from basic math and type conversion to advanced iterable processing and input/output operations. Knowing them well can drastically shorten your code and make it more readable.
Math and Number Functions
abs()returns the absolute value of a number.round()rounds a float to a given precision.pow()raises a number to a power (equivalent to**but with an optional modulus).sum()calculates the sum of an iterable of numbers.min()andmax()return the smallest or largest item in an iterable.
These are simple but indispensable for numeric operations.
Data Type Conversion and Creation
Python provides functions to convert between types:
int(),float(),str(),bool(),list(),tuple(),set(),dict()– each creates an instance of the corresponding type from an input.bytes(),bytearray(),memoryview()handle binary data.chr()andord()convert between characters and Unicode code points.
These functions are your go-to for ensuring data is in the right shape before processing.
Iterable and Sequence Helpers
len()returns the length of a sequence or collection.enumerate()adds an index to an iterable, perfect for loops.zip()pairs elements from multiple iterables.reversed()returns an iterator that yields items in reverse order.sorted()returns a new sorted list from any iterable.
These functions make working with loops and data collections more expressive and Pythonic.
Functional Tools
map()applies a function to every item in an iterable.filter()keeps only items that satisfy a predicate.reduce()(fromfunctools) is not built-in but commonly used; however, built-insum(),any(),all()cover many reduction needs.any()andall()check if any or all items in an iterable are truthy.
These enable a functional programming style without heavy imports.
Input/Output and System
print()outputs to the console.input()reads a line from standard input.open()opens a file for reading or writing.help()anddir()are invaluable for exploration in the interactive interpreter.
These are the gateways to interacting with the user and the filesystem.
Advanced: eval(), exec(), and compile()
While powerful, these functions execute arbitrary code and should be used with caution. They allow dynamic code execution, but they also pose security risks if used with untrusted input.
Putting It All Together
Python's built-in functions are designed to be intuitive and consistent. Instead of writing custom loops for common tasks, you can often combine a few built-ins to achieve the same result in a single line. This not only reduces boilerplate but also makes your code more maintainable and less error-prone.
For example, to find the average of numbers in a list, you can do sum(numbers) / len(numbers). To filter out empty strings, use filter(None, strings).
By investing time in learning these functions, you'll write more idiomatic Python and solve problems faster. They are the foundation of the language's philosophy: simple, readable, and powerful.