str, bytes, list, dict, and set carry built-in methods, plus a small set on int and float. The set is curated for common operations. Missing variants are noted per section.
tuple and frozenset have no methods. (1, 2).count(1) raises AttributeError. Frozensets use the algebra operators from Set instead.
HELLO
1
1String methods
Case transforms
upper, lower, capitalize, title, casefold, swapcase. title titlecases each maximal run of letters. casefold is aggressive lowercasing for caseless comparison.
HELLO
hello
Hello world
Hello World
hello
hELLO wORLDWhitespace
strip, lstrip, rstrip remove whitespace, or any character in the optional string argument.
hi
hi
hi
helloPredicates
isdigit, isalpha, isalnum, isspace, isupper, islower, istitle. All return False on an empty string. The cased predicates also require at least one cased character. isdigit is Unicode-aware.
True
True
True
True
True
True
TrueNot provided: isascii, isidentifier, isnumeric, isdecimal, isprintable.
Search and count
find and rfind return a code-point index, or -1 on a miss. index and rindex raise ValueError on a miss. count counts non-overlapping occurrences. startswith and endswith accept a single string or a tuple of strings. All of these take optional start and end code-point bounds.
True
True
2
5
3
-1
2Split, join, replace
split() with no argument (or None) splits on whitespace runs. An explicit separator splits on every occurrence, and an empty separator raises ValueError. split and rsplit take an optional maxsplit. replace(old, new) takes an optional count cap. splitlines() drops the line separators and has no keepends mode. partition and rpartition split once into a (head, sep, tail) tuple. removeprefix and removesuffix strip an affix when present.
['a', 'b', 'c']
['a', 'b,c']
['a b', 'c']
['hello', 'world']
a,b,c
bbaa
bar
['a', 'b', 'c']
('foo', ':', 'bar:baz')
('foo:bar', ':', 'baz')Padding
center, ljust, rjust take (width[, fill]). zfill(width) pads with leading zeros after any sign. Widths are measured in code points, not bytes. A multi-character fill raises TypeError. expandtabs([tabsize]) replaces tabs with spaces up to the next tab stop, default 8.
--abc--
hi...
...hi
00042
-0042
a bc
**ñ**Not provided: translate, maketrans, format_map.
Formatting
str.format(*args) fills positional fields. {} auto-numbers and {0} picks an index. A spec after : uses the format mini-language. Keyword fields like {name} are not supported.
The % operator does printf-style formatting. Supported verbs are %s %r %d %i %u %x %X %o %f %F %e %E %g %G %c %%, with flags, width, and .precision. * reads the width or precision from the next argument. A tuple on the right spreads into the fields, any other value is a single argument.
a and b
x-y-x
hi
3 apples, 1.5 kg
03.10|hi |Encoding
s.encode([encoding]) returns bytes. The encodings are "utf-8" (the default), "utf8", and "ascii". ASCII raises ValueError on non-ASCII input, and any other encoding name raises ValueError.
b'caf\xc3\xa9'
b'hi'Bytes methods
decode([encoding[, errors]]) returns a string. The encodings match str.encode. The errors handler is "strict" (the default, raises ValueError on invalid UTF-8), "ignore" (drops bad bytes), or "replace" (substitutes U+FFFD).
hex() returns lowercase hex with no separator option. startswith and endswith take a single bytes value, no tuple form. find returns a byte offset or -1, and index raises ValueError on a miss. count counts non-overlapping occurrences. replace(old, new) has no count cap. split(sep) requires an explicit separator. lower and upper case-fold ASCII bytes only. strip, lstrip, rstrip trim ASCII whitespace or any byte in the optional argument. join concatenates an iterable of bytes. bytes.fromhex(s) parses a hex string, ignoring whitespace.
bytearray and memoryview do not exist.
Hello
48656c6c6f
True
True
2
2
b'HeLLo'
[b'a', b'b', b'c']
b'abc'
b'hi'
b'a-b-c'
b'Hello'
�List methods
Query
index(value[, start[, end]]) returns the first match and raises ValueError on a miss. Negative bounds count from the end. count(value) counts matches. copy() returns a shallow copy.
1
3
2
[1, 2, 3, 2]
[1, 2, 3, 2, 99]Mutating
These return None and mutate in place. append(x) adds one item. extend(iter) adds every item of any iterable. insert(i, x) inserts at an index. remove(x) deletes the first match and raises ValueError on a miss. pop() removes and returns the last item, pop(i) by index. Both raise IndexError when the index is invalid. sort() accepts key=fn and reverse=True and orders objects by their __lt__. reverse() flips in place. clear() empties the list.
[99, 1, 2, 3, 4, 5, 6]
6 [1, 2, 3, 4, 5]
1 [2, 3, 4, 5][1, 1, 3, 4, 5]
[5, 4, 3, 1, 1]
['kiwi', 'apple', 'banana']Dict methods
Views
keys, values, items return concrete list snapshots, not live views. Later mutations of the dict do not affect a captured snapshot.
['a', 'b', 'c']
[1, 2, 3]
[('a', 1), ('b', 2), ('c', 3)]
['a', 'b', 'c']Lookup
get(key) returns the value or None. get(key, default) returns default on a miss.
1
None
0Mutation
update(src) merges a dict, an iterable of length-2 pairs, or keyword arguments. pop(key) removes and returns the value, raising KeyError on a miss unless a default is given. popitem() removes and returns the last-inserted (key, value) pair and raises KeyError on an empty dict. setdefault(key, default) inserts only when the key is missing and returns the stored value. clear() empties the dict in place, so aliases see the change. copy() returns a shallow copy. dict.fromkeys(iterable[, value]) builds a new dict mapping each key to value, default None.
{'a': 99, 'b': 2, 'c': 3, 'e': 5}
99 {'b': 2, 'c': 3, 'e': 5}
fallback
2
{'x': 0, 'y': 0}
('e', 5)Set methods
These exist on set only. Frozensets use the operators and comparisons from Set.
Mutation
add(x) inserts. remove(x) deletes and raises KeyError on a miss. discard(x) deletes silently. pop() removes and returns an arbitrary element and raises KeyError on an empty set. update(*iterables) inserts from any number of iterables. clear() empties the set. copy() returns a shallow copy.
{2, 4, 1, 3}
{4, 1, 3}
True
set()Algebra
union, intersection, difference return fresh sets and accept any number of iterable arguments. symmetric_difference takes exactly one. intersection_update, difference_update, symmetric_difference_update mutate the receiver. issubset, issuperset, isdisjoint test relations. The named methods accept any iterable, while the operator forms (|, &, -, ^) require a set or frozenset on both sides.
{5, 2, 4, 1, 3}
{3}
{1, 2}
{5, 2, 4, 1}
[1, 2, 3, 4, 5]
{2, 4}
True
True
Trueint and float methods
int exposes bit_length() (bits needed for the absolute value, 0 for zero), bit_count() (number of set bits), and to_bytes(length=1, byteorder='big') (unsigned, OverflowError when the value does not fit or is negative). int.from_bytes(bytes, byteorder='big') is a classmethod, unsigned, raising OverflowError past the 128-bit range. float exposes is_integer().
8
8
b'\x03\xe8'
b'\xe8\x03'
1000
True
FalseThe standalone int_to_bytes, int_from_bytes, bytes_fromhex functions do similar jobs but are fixed-arity, capped at 8 bytes, and reject negative ints with ValueError.