Python Data Types and Their Methods
INT METHODS
bit_length():
Returns the number of bits necessary to represent the integer in binary.
to_bytes(length, byteorder):
Returns an array of bytes representing the integer.
from_bytes(bytes, byteorder):
Returns the integer represented by the given array of bytes.
STR METHODS
upper():
Converts all lowercase letters in a string to uppercase.
lower():
Converts all uppercase letters in a string to lowercase.
find(sub):
Returns the lowest index of the substring if found, otherwise -1.
replace(old, new):
Returns a copy of the string with all occurrences of substring old replaced by new.
LIST METHODS
append(x):
Adds an item x to the end of the list.
extend(iterable):
Extends the list by appending elements from the iterable.
insert(i, x):
Inserts an item x at a given position i.
remove(x):
Removes the first item from the list whose value is equal to x.
pop([i]):
Removes the item at the given position in the list, and returns it.
TUPLE METHODS
count(x):
Returns the number of times x appears in the tuple.
index(x):
Returns the first index of value x in the tuple.
DICT METHODS
get(key):
Returns the value for key if key is in the dictionary.
keys():
Returns a new view of the dictionary's keys.
values():
Returns a new view of the dictionary's values.
items():
Returns a new view of the dictionary's items (key, value pairs).
update([other]):
Updates the dictionary with the key/value pairs from other, overwriting existing keys.
SET METHODS
add(x):
Adds element x to the set.
remove(x):
Removes element x from the set. Raises KeyError if not present.
discard(x):
Removes element x from the set if it is present.
union(other):
Returns the union of sets as a new set.
intersection(other):
Returns the intersection of sets as a new set.