Built-in Functions
A selection of frequently used built-in functions.
| Function | Description |
|---|---|
abs(x) | Absolute value |
len(x) | Number of items |
type(x) | Type of object |
print(*args) | Write to stdout |
input(prompt) | Read a line of text |
int(x) / float(x) / str(x) | Type conversion |
range(stop) | Sequence of numbers |
enumerate(iterable) | Index + value pairs |
zip(*iterables) | Combine iterables |
map(fn, iterable) | Apply function to each item |
filter(fn, iterable) | Keep items where fn is true |
sorted(iterable) | Return a new sorted list |
sum(iterable) | Sum of items |
min(iterable) / max(iterable) | Smallest / largest |
open(path, mode) | Open a file |
isinstance(obj, t) | Type check |
hasattr(obj, name) | Attribute check |
dir(obj) | List attributes |
help(obj) | Interactive help |
Example
print(len([1, 2, 3]), sum([1, 2, 3]), sorted([3, 1, 2]))