Python functions
Built-in functions, string and list methods, dictionary and set operations. Every entry with a LIVE pill has a live in-browser demo.
Methods on the built-in string type. Immutable — every method returns a new string.
LIVE
str.capitalize
capitalize()
Return a copy with the first character titlecased and the rest lowercased.
LIVEstr.endswith
endswith(suffix, start=0, end=len(s))
Test whether the string ends with a suffix.
LIVEstr.find
find(sub, start=0, end=len(s))
Return the lowest index of a substring, or -1 if absent.
LIVEstr.isdigit
isdigit()
Test whether all characters are digits and the string is non-empty.
LIVEstr.join
join(iterable)
Concatenate an iterable of strings with this string as the separator.
LIVEstr.lower
lower()
Return a copy of the string with all cased characters lowercased.
LIVEstr.replace
replace(old, new, count=-1)
Return a copy with all occurrences of old replaced by new.
LIVEstr.rstrip
rstrip(chars=None)
Return a copy with trailing characters removed.
LIVEstr.split
split(sep=None, maxsplit=-1)
Break a string into a list of substrings on a delimiter.
LIVEstr.startswith
startswith(prefix, start=0, end=len(s))
Test whether the string begins with a prefix.
LIVEstr.casefold
casefold()
Aggressive lowercase for case-insensitive comparison — stronger than lower().
LIVEstr.center
center(width, fillchar=" ")
Center within a given width, padding both sides.
LIVEstr.count
count(sub, start=0, end=len(s))
Count non-overlapping occurrences of a substring.
LIVEstr.encode
encode(encoding="utf-8", errors="strict")
Convert a string to bytes using the given encoding — the string-to-bytes boundary.
LIVEstr.expandtabs
expandtabs(tabsize=8)
Replace tabs with spaces to align at the next tab stop — not with a fixed number of spaces.
LIVEstr.format
format(*args, **kwargs)
Fill `{}` placeholders — positional, numbered, or named — with the format spec after the colon.
LIVEstr.format_map
format_map(mapping)
Like format(**mapping), but without copying the mapping first.
LIVEstr.index
index(sub[, start[, end]])
Position of the first occurrence — raises ValueError instead of returning -1.
LIVEstr.isalnum
isalnum()
True if every character is a letter or digit and the string is non-empty.
LIVEstr.isalpha
isalpha()
True if every character is alphabetic and the string is non-empty.
LIVEstr.isascii
isascii()
True if every character is in the ASCII range (0..127) — empty string also True.
LIVEstr.isdecimal
isdecimal()
The narrowest numeric check — decimal digits only, no superscripts, no fractions.
LIVEstr.isidentifier
isidentifier()
True if the string could be a valid Python identifier — reserved keywords also pass.
LIVEstr.islower
islower()
True if every cased character is lowercase and the string has at least one cased character.
LIVEstr.isnumeric
isnumeric()
True if every character is numeric — including Roman numerals and fractions.
LIVEstr.isprintable
isprintable()
True if every character is printable and the string has no control characters — empty is True.
LIVEstr.isspace
isspace()
True if every character is whitespace and the string is non-empty.
LIVEstr.istitle
istitle()
True if the string is in strict title case — first letter of each word uppercase, rest lowercase.
LIVEstr.isupper
isupper()
True if every cased character is uppercase and the string has at least one cased character.
LIVEstr.ljust
ljust(width, fillchar=" ")
Left-align within a given width — pad on the right.
LIVEstr.lstrip
lstrip(chars=None)
Strip leading whitespace — or leading characters from a given set.
LIVEstr.maketrans
maketrans(x[, y[, z]])
Build a translation table for str.translate — three call shapes.
LIVEstr.partition
partition(sep)
Split at the first occurrence of sep — always into three pieces.
LIVEstr.removeprefix
removeprefix(prefix)
Remove an exact leading substring — safer than lstrip for prefix stripping.
LIVEstr.removesuffix
removesuffix(suffix)
Remove an exact trailing substring — safer than rstrip for suffix stripping.
LIVEstr.rfind
rfind(sub, start=0, end=len(s))
Return the highest index of a substring, or -1 if absent.
LIVEstr.rindex
rindex(sub[, start[, end]])
Position of the LAST occurrence — raises ValueError instead of returning -1.
LIVEstr.rjust
rjust(width, fillchar=" ")
Right-align within a given width — pad on the left.
LIVEstr.rpartition
rpartition(sep)
Split at the LAST occurrence of sep — always into three pieces.
LIVEstr.rsplit
rsplit(sep=None, maxsplit=-1)
Split from the right — behaves like split unless maxsplit is set.
LIVEstr.splitlines
splitlines(keepends=False)
Split at universal newlines — no trailing empty string.
LIVEstr.swapcase
swapcase()
Flip case per character — uppercase becomes lowercase and vice versa.
LIVEstr.translate
translate(table)
Apply a character-mapping table — replace, delete, or transform in one pass.
LIVEstr.strip
strip(chars=None)
Return a copy with leading and trailing characters removed.
LIVEstr.title
title()
Return a titlecased copy — every word starts uppercase.
LIVEstr.upper
upper()
Return a copy of the string with all cased characters uppercased.
LIVEstr.zfill
zfill(width)
Left-pad with zeros to a given width, sign-aware.