Loading...
Preparing your coding drills
Comprehensive reference for 76 Python methods across 5 categories.
append
Adds an element to the end of the list. Modifies the list in place.
extend
Extends the list by appending all elements from the iterable.
insert
Inserts an element at a given position. All elements after it are shifted right.
remove
Removes the first occurrence of a value. Raises ValueError if not present.
pop
Removes and returns the element at the given position. Defaults to the last element.
index
Returns the index of the first occurrence of the specified element.
count
Returns the number of times the specified element appears in the list.
sort
Sorts the list in place. Can use a custom key function and reverse order.
reverse
Reverses the elements of the list in place.
copy
Returns a shallow copy of the list.
clear
Removes all elements from the list.
split
Splits the string at the specified separator and returns a list of substrings.
join
Joins elements of an iterable with the string as separator.
strip
Returns a copy of the string with leading and trailing characters removed.
replace
Returns a copy with all occurrences of substring old replaced by new.
find
Returns the lowest index where substring is found, or -1 if not found.
startswith
Returns True if the string starts with the specified prefix.
endswith
Returns True if the string ends with the specified suffix.
upper
Returns a copy of the string with all characters converted to uppercase.
lower
Returns a copy of the string with all characters converted to lowercase.
isdigit
Returns True if all characters in the string are digits.
isalpha
Returns True if all characters in the string are alphabetic.
format
Performs string formatting with positional and keyword arguments.
zfill
Pads the string with zeros on the left to fill the specified width.
title
Returns a titlecased version where words start with uppercase and remaining chars are lowercase.
capitalize
Returns a copy with only the first character capitalized and the rest lowercased.
casefold
Returns a casefolded copy for caseless matching. More aggressive than lower().
lstrip
Returns a copy with leading characters removed.
rstrip
Returns a copy with trailing characters removed.
center
Returns a centered string of specified width, padded with fillchar.
ljust
Returns a left-justified string of specified width, padded on the right.
rjust
Returns a right-justified string of specified width, padded on the left.
rfind
Returns the highest index where substring is found, or -1 if not found.
partition
Splits the string at the first occurrence of sep, returning a 3-tuple.
rpartition
Splits the string at the last occurrence of sep, returning a 3-tuple.
get
Returns the value for key if key is in the dictionary, else default.
keys
Returns a view object displaying all keys in the dictionary.
values
Returns a view object displaying all values in the dictionary.
items
Returns a view object displaying all key-value pairs as tuples.
update
Updates the dictionary with key-value pairs from another dictionary or iterable.
Removes and returns the value for key. If key is not found, returns default or raises KeyError.
setdefault
Returns value for key if it exists, otherwise inserts key with default value and returns default.
fromkeys
Creates a new dictionary with keys from iterable and values set to value.
Returns a shallow copy of the dictionary.
Removes all items from the dictionary.
popitem
Removes and returns a (key, value) pair as a tuple. LIFO order (Python 3.7+).
len
Returns the number of items in an object (sequence or collection).
range
Returns an immutable sequence of numbers from start to stop with step increment.
enumerate
Returns an enumerate object yielding pairs of (index, value).
zip
Returns an iterator of tuples, where the i-th tuple contains the i-th element from each input iterable.
map
Returns an iterator that applies function to every item of iterable.
filter
Returns an iterator yielding items for which function returns True.
sorted
Returns a new sorted list from the items in iterable.
reversed
Returns a reverse iterator over the values of the given sequence.
sum
Returns the sum of all items in the iterable plus the start value.
min
Returns the smallest item in an iterable or the smallest of two or more arguments.
max
Returns the largest item in an iterable or the largest of two or more arguments.
abs
Returns the absolute value of a number.
any
Returns True if any element of the iterable is truthy. Returns False if the iterable is empty.
all
Returns True if all elements of the iterable are truthy. Returns True if the iterable is empty.
round
Returns number rounded to ndigits precision after the decimal point.
pow
Returns base to the power exp; with mod, returns (base**exp) % mod.
divmod
Returns a tuple of quotient and remainder when dividing a by b.
isinstance
Returns True if object is an instance of classinfo or its subclass.
type
Returns the type of an object.
hasattr
Returns True if the object has the given named attribute.
getattr
Returns the value of the named attribute of object.
callable
Returns True if the object appears callable.
add
Adds an element to the set.
discard
Removes an element from the set if present. Does nothing if not present.
union
Returns a new set with elements from the set and all others.
intersection
Returns a new set with elements common to the set and all others.
difference
Returns a new set with elements in the set that are not in the others.
symmetric_difference
Returns a new set with elements in either set but not in both.
issubset
Returns True if all elements of the set are in other.
issuperset
Returns True if all elements of other are in the set.