Home Cheat Sheets Python Built-in Functions Cheat Sheet
📋 CHEAT SHEET

Python Built-in Functions Cheat Sheet

Complete reference for Python built-in functions — type conversion, math, sequences, I/O and more with examples.

Read Full Tutorial →

Type Conversion

FunctionExampleReturns
int(x)int('42') → 42Integer
float(x)float('3.14') → 3.14Float
str(x)str(42) → '42'String
bool(x)bool(0) → FalseBoolean
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') → 65Integer
hex(x)hex(255) → '0xff'Hex string
bin(x)bin(10) → '0b1010'Binary string
oct(x)oct(8) → '0o10'Octal string

Math & Numbers

FunctionExampleReturns
abs(x)abs(-5) → 5Absolute value
round(x, n)round(3.14159, 2) → 3.14Rounded number
pow(x, y)pow(2, 10) → 1024x to the power y
divmod(x, y)divmod(17, 5) → (3, 2)(quotient, remainder)
max(iterable)max([1,5,3]) → 5Maximum value
min(iterable)min([1,5,3]) → 1Minimum value
sum(iterable)sum([1,2,3]) → 6Sum of values

Sequences & Iterables

FunctionExampleReturns
len(x)len([1,2,3]) → 3Length
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

I/O & Objects

FunctionDescription
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
More Cheat Sheets
Java Collections Cheat SheetJava Streams API Cheat SheetSQL Joins Cheat SheetDocker Commands Cheat SheetJVM Memory Model DiagramHow HashMap Works InternallyMicroservices Architecture DiagramPandas Cheat Sheet