Built-in methods on str, bytes, list, dict, set, plus a small set on int and float. The set is curated for common operations. Rarely used variants are omitted, documented per section.
int exposes bit_length, bit_count, to_bytes, and the from_bytes classmethod; float exposes is_integer (see int / float methods). tuple has no methods: (1, 2).count(1) raises AttributeError; use sum(1 for x in t if x == v).
HELLO
1
1String methods
Case transforms
title titlecases each word (a maximal run of letters); digits and punctuation are word boundaries. casefold is aggressive lowercasing for caseless comparison. swapcase flips each letter’s case.
HELLO
hello
Hello world
Hello World
hello
hELLO wORLDWhitespace
hi
hi
hi
helloPredicates
isdigit (Unicode-aware), isalpha, isalnum, isspace, plus the cased predicates isupper / islower / istitle. The cased ones need at least one cased character. All return False on empty string.
True
True
True
True
True
True
TrueNot provided: isascii, isidentifier, isnumeric, isdecimal, isprintable. Write the predicate explicitly.
Search and count
find / rfind return a code-point index (not a byte offset), -1 if missing. index / rindex raise ValueError instead of returning -1. find, rfind, index, rindex, count take optional start / end code-point positions. startswith / endswith accept a single string or a tuple of strings.
True
True
True
2
5
3
-1
2Split, join, replace
split with no arg (or None) splits on whitespace runs. An explicit separator splits on every occurrence; an empty separator raises ValueError. Both split and rsplit take an optional maxsplit. replace takes an optional count cap. splitlines drops separators (no keepends) and recognises \n \r \r\n \v \f and the Unicode line breaks.
['a', 'b', 'c']
['a', 'b,c']
['a b', 'c']
['hello', 'world']
a,b,c
bbaa
bar
foo
['a', 'b', 'c']
('foo', ':', 'bar:baz')
('foo:bar', ':', 'baz')Padding
center, ljust, rjust take (width[, fill]); zfill(width) pads with leading zeros. All measure in code points, not bytes, so 'ñ'.center(5, '*') produces **ñ** (5 visible chars). A multi-character fill raises TypeError. expandtabs([tabsize]) replaces tabs with spaces to the next tab stop (default 8). Not provided: translate, maketrans, format_map.
--abc--
hi...
...hi
00042
-0042
a bcFormatting
str.format(*args) fills positional fields ({} auto-numbered, {0} explicit) with the f-string format mini-language after :. Keyword fields ("{name}".format(name=...)) are not supported, use positional indices. The % operator does printf-style formatting (%s %r %d %i %x %X %o %f %e %g %c %%, with flags / width / .precision); a tuple spreads, any other value is a single argument.
a and b
x-y-x
hi
1,234,567
3 apples, 1.5 kg
03.10|hi |Encoding
s.encode([encoding]) -> bytes. Supports "utf-8", "utf8", "ascii" (errors on non-ASCII). Else ValueError. Default "utf-8".
b'caf\xc3\xa9'
b'hi'Bytes methods
bytes.decode([encoding[, errors]]) takes encoding (utf-8 or ascii) and an errors handler: strict (default) raises on invalid UTF-8, ignore drops the bad bytes, replace substitutes U+FFFD. bytes.find returns a byte offset (not a code-point index). bytes.index raises ValueError if absent. split needs an explicit separator (no whitespace-split mode). lower / upper case-fold ASCII bytes; strip / lstrip / rstrip trim ASCII whitespace (or any byte in the optional set). join concatenates an iterable of bytes. bytes.fromhex(s) parses a hex string (whitespace ignored). bytearray and memoryview are unimplemented.
Hello
48656c6c6f
True
2
2
b'HeLLo'
[b'a', b'b', b'c']
b'abc'
b'hi'
b'a-b-c'
b'Hello'List methods
Pure (return a new value or query)
index accepts optional start / end bounds (negatives count from the end) and raises ValueError if the value isn’t found in that range; copy returns a shallow copy.
1
3
2
[1, 2, 3, 2]
[1, 2, 3, 2, 99]Mutating
Return None, mutate in place. extend accepts any iterable. sort accepts key=fn and reverse=True/False.
[1, 2, 3, 4]
[1, 2, 3, 4, 5, 6]
[99, 1, 2, 3, 4, 5, 6][1, 3, 2]
2 [1, 3]
1 [3][1, 1, 3, 4, 5]
[5, 4, 3, 1, 1]
[]Dict methods
Views
keys, values, items return concrete list snapshots, not live views. Dict mutations don’t affect captured snapshots. This is intentional: live views are shared mutable state, which conflicts with the functional paradigm.
['a', 'b', 'c']
[1, 2, 3]
[('a', 1), ('b', 2), ('c', 3)]
['a', 'b', 'c']Lookup with default
1
None
0Mutation
update accepts a dict, an iterable of length-2 sequences, or keyword arguments (d.update(a=1)). popitem returns the last-inserted entry; empty -> KeyError. pop(key) on a missing key -> KeyError unless a default is given. The dict.fromkeys(iterable[, value]) classmethod builds a new dict mapping each key to value (default None). No clear.
{'a': 99, 'b': 2}
{'a': 99, 'b': 2, 'c': 3, 'e': 5}
99 {'b': 2, 'c': 3, 'e': 5}
fallback
{'x': 0, 'y': 0}{'a': 1}Set methods
These are set-only. frozenset exposes no methods; it uses the algebra operators (| & - ^) and comparisons instead. See Frozenset.
Mutation
remove raises KeyError if absent. discard is silent. pop removes an arbitrary element; empty -> KeyError. update accepts any iterable (variadic).
{2, 3, 4, 1}
{3, 4, 1}
True
set()Algebra
union, intersection, difference return fresh sets and accept any number of iterable arguments; symmetric_difference takes exactly one. The in-place intersection_update, difference_update, symmetric_difference_update mutate the receiver. Operator forms (|, &, -, ^) and augmented assignment (|=, &=, -=, ^=) require both sides to be a set or frozenset; the named methods accept any iterable.
{5, 3, 2, 1, 4}
{3}
{2, 1}
{1, 4, 5, 2}
{3, 1, 4, 2, 5}
{4, 2}
True
True
TrueComparison operators between sets follow subset / superset semantics, not total order:
True
True
True
Falseint and float methods
Small set on the numeric primitives. int exposes bit_length() (bits to represent the absolute value, 0 for 0), bit_count() (number of set bits), and to_bytes(length=1, byteorder='big') (unsigned big/little-endian, OverflowError if it doesn’t fit). int.from_bytes(bytes, byteorder='big') is a classmethod. float exposes is_integer().
8
8
b'\x03\xe8'
b'\xe8\x03'
1000
True
FalseThe standalone int_to_bytes / int_from_bytes / bytes_fromhex builtin functions remain available and behave identically.