Python Built-in Functions Cheat Sheet
Reference guide to Python's built-in functions. Learn how to use print, len, range, enumerate, zip, map, filter, and more.
Utility & Sequence Functions
Pre-defined helper routines designed for managing sequence indexing and structures.
| Method | Syntax | Description |
|---|---|---|
| len() | len(s) | Returns the length (number of items) of an object. |
| range() | range(start, stop, [step]) | Returns an immutable sequence of numbers starting from start up to stop. |
| enumerate() | enumerate(iterable, start=0) | Returns an enumerate object yielding tuples containing index and value. |
| zip() | zip(*iterables) | Returns an iterator of tuples aggregation corresponding values across inputs. |
| sorted() | sorted(iterable, key=None, reverse=False) | Returns a new sorted list from the items in iterable. |
| reversed() | reversed(seq) | Returns a reverse iterator over the values of a sequence. |
Evaluation & Functional Tools
Routines supporting verification, aggregation, and mathematical reduction.
| Method | Syntax | Description |
|---|---|---|
| map() | map(function, iterable) | Applies function to all items in iterable and returns an iterator. |
| filter() | filter(function, iterable) | Constructs an iterator from elements of iterable for which function returns true. |
| any() | any(iterable) | Returns True if at least one element of the iterable evaluates to True. |
| all() | all(iterable) | Returns True if all elements of the iterable evaluate to True. |
| sum() | sum(iterable, start=0) | Sums start and the items of an iterable from left to right. |
| round() | round(number, ndigits=None) | Rounds a number to ndigits decimal precision. |
Frequently Asked Questions
How does zip() handle iterables of different lengths?
By default, zip() stops when the shortest iterable is exhausted. In Python 3.10+, you can pass strict=True to raise a ValueError if lengths differ.
What is the difference between sorted() and list.sort()?
sorted() returns a new sorted list and accepts any iterable, whereas list.sort() sorts the list in-place and returns None.
Keep Learning
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Functions
Master Python functions. Learn how to write reusable code using def, define arguments, return values, and understand scope locally and globally.
How to Reverse a String in Python
Learn how to reverse a string in Python using slicing, the reversed() function, and loop concatenation with visual code examples.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.