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.

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

String Methods

MethodReturnsExample
str.split(sep)List of substrings'a,b,c'.split(',') → ['a','b','c']
str.join(iterable)String joined by separator','.join(['a','b','c']) → 'a,b,c'
str.strip() / lstrip() / rstrip()String with whitespace removed' hi '.strip() → 'hi'
str.replace(old, new)New string with replacements'hello'.replace('l','r') → 'herro'
str.startswith() / endswith()bool'hello'.startswith('he') → True
str.find(sub) / index(sub)First index or -1 / raises ValueError'hello'.find('ll') → 2
str.upper() / lower() / title()Case-converted string'hello world'.title() → 'Hello World'
str.zfill(width)Zero-padded string'42'.zfill(5) → '00042'
str.format() / f-stringFormatted stringf'{name!r} is {age:03d}'

Comprehensions

TypeSyntaxExample
List comprehension[expr for x in iterable if cond][x**2 for x in range(10) if x%2==0]
Dict comprehension{k: v for k, v in iterable}{w: len(w) for w in words}
Set comprehension{expr for x in iterable}{x%3 for x in range(9)} → {0,1,2}
Generator expression(expr for x in iterable)sum(x**2 for x in range(100)) — lazy, no list built
Nested comprehension[expr for x in outer for y in inner][x*y for x in [1,2] for y in [3,4]]
Conditional expressionval_if_true if cond else val_if_false['even' if x%2==0 else 'odd' for x in range(5)]
More Cheat Sheets
Java Collections Cheat SheetJava Streams API Cheat SheetSQL Joins Cheat SheetDocker Commands Cheat SheetJVM Memory Model DiagramHow HashMap Works InternallyMicroservices Cheat SheetPandas Cheat SheetData Structures & Algorithms Cheat Sheet