Python Functions & Methods – Cheat Sheet with
Examples
Built-in Functions
• len(x) → length of object | Example: len([1,2,3])
• type(x) → data type | Example: type(10)
• sum(iterable) | Example: sum([1,2,3])
• min(), max() | Example: max([4,7,1])
• range(start, stop, step) | Example: range(1,5)
• sorted(iterable) | Example: sorted([3,1,2])
List Methods
• append(x) | Example: [Link](5)
• insert(i, x) | Example: [Link](1, 10)
• extend(iterable) | Example: [Link]([3,4])
• remove(x) | Example: [Link](2)
• pop() | Example: [Link]()
• sort() | Example: [Link]()
Dictionary Methods
• keys() | Example: [Link]()
• values() | Example: [Link]()
• items() | Example: [Link]()
• get(key) | Example: [Link]('a')
• update(dict) | Example: [Link]({'b':2})
String Methods
• upper() | Example: [Link]()
• lower() | Example: [Link]()
• split() | Example: [Link]()
• replace(a,b) | Example: [Link]('a','b')
• startswith() | Example: [Link]('py')
Set Methods
• add(x) | Example: [Link](3)
• remove(x) | Example: [Link](2)
• union() | Example: [Link](s2)
• intersection() | Example: [Link](s2)