Complete reference for Python built-in functions — type conversion, math, sequences, I/O and more with examples.
| Function | Example | Returns |
|---|---|---|
| int(x) | int('42') → 42 | Integer |
| float(x) | float('3.14') → 3.14 | Float |
| str(x) | str(42) → '42' | String |
| bool(x) | bool(0) → False | Boolean |
| list(x) | list('abc') → ['a','b','c'] | List |
| tuple(x) | tuple([1,2]) → (1,2) | Tuple |
| set(x) | set([1,1,2]) → {1,2} | Set |
| dict(x) | dict(a=1) → {'a':1} | Dict |
| bytes(x) | bytes(3) → b'\x00\x00\x00' | Bytes |
| chr(x) | chr(65) → 'A' | Character |
| ord(x) | ord('A') → 65 | Integer |
| hex(x) | hex(255) → '0xff' | Hex string |
| bin(x) | bin(10) → '0b1010' | Binary string |
| oct(x) | oct(8) → '0o10' | Octal string |
| Function | Example | Returns |
|---|---|---|
| abs(x) | abs(-5) → 5 | Absolute value |
| round(x, n) | round(3.14159, 2) → 3.14 | Rounded number |
| pow(x, y) | pow(2, 10) → 1024 | x to the power y |
| divmod(x, y) | divmod(17, 5) → (3, 2) | (quotient, remainder) |
| max(iterable) | max([1,5,3]) → 5 | Maximum value |
| min(iterable) | min([1,5,3]) → 1 | Minimum value |
| sum(iterable) | sum([1,2,3]) → 6 | Sum of values |
| Function | Example | Returns |
|---|---|---|
| len(x) | len([1,2,3]) → 3 | Length |
| range(start,stop,step) | range(0,10,2) | Range object |
| enumerate(x) | enumerate(['a','b']) | (index, value) pairs |
| zip(*iterables) | zip([1,2],[3,4]) | Tuples of paired items |
| map(func, iterable) | map(str, [1,2,3]) | Map object |
| filter(func, iterable) | filter(None, [0,1,2]) | Filter object |
| sorted(x, key, reverse) | sorted([3,1,2]) | New sorted list |
| reversed(x) | list(reversed([1,2,3])) | Reversed iterator |
| any(iterable) | any([False,True]) | True if any truthy |
| all(iterable) | all([True,True]) | True if all truthy |
| Function | Description |
|---|---|
| print(*args, sep, end) | Print to stdout |
| input(prompt) | Read line from stdin |
| open(file, mode) | Open file — returns file object |
| type(x) | Return type of object |
| isinstance(x, type) | Check if x is instance of type |
| id(x) | Unique integer identity of object |
| dir(x) | List attributes and methods |
| help(x) | Show documentation |
| vars(x) | Return __dict__ of object |
| callable(x) | True if x can be called |
| hasattr(x, name) | True if x has attribute |
| getattr(x, name) | Get attribute value |
| setattr(x, name, val) | Set attribute value |