Tuple Methods :
t = (1, 2, 3)
t.count(2) # 1
t.index(3) # 2
Tuple Methods :
t = (1, 2, 3)
t.count(2) # 1
t.index(3) # 2
List Methods :
lst = [1, 2, 3]
lst.append(4) # [1, 2, 3, 4]
lst.extend([5, 6]) # [1, 2, 3, 4, 5, 6]
lst.insert(1, 10) # [1, 10, 2, 3, ...]
lst.remove(10) # Removes first match
lst.pop() # Removes last and returns it
lst.pop(1) # Removes and returns index 1
lst.clear() # []
lst.index(3) # Returns index of 3
lst.count(2) # Count of 2s
lst.sort() # In-place sort
lst.reverse() # In-place reverse
sorted(lst) # Returns sorted copy
Integer methods
x = 42
float(x) # 42.0
int(3.14) # 3
abs(-5) # 5
round(3.75) # 4
pow(2, 3) # 8
divmod(9, 4) # (2, 1)
bin(10) # '0b1010'
hex(255) # '0xff'
oct(8) # '0o10'
Methods :
s = "hello world"
s.upper() # 'HELLO WORLD'
s.lower() # 'hello world'
s.capitalize() # 'Hello world'
s.title() # 'Hello World'
s.strip() # Remove whitespace
s.lstrip() # Left-strip
s.rstrip() # Right-strip
s.replace("l", "x") # 'hexxo worxd'
s.split(" ") # ['hello', 'world']
s.join(['a', 'b']) # 'a b'
s.startswith("he") # True
s.endswith("ld") # True
s.find("o") # First index (4)
s.rfind("o") # Last index (7)
s.count("l") # 3
s.isalpha() # False
s.isdigit() # False
s.isalnum() # False
s.islower() # True
s.isupper() # False
s.swapcase() # 'HELLO WORLD'
s.zfill(12) # '00hello world'
s.center(20, "-") # '----hello world-----'
Tuple Methods : t = (1, 2, 3) t.count(2) # 1 t.index(3) # 2 #Set methods : s = {1, 2, 3} s.add(4) # {1, ...