Python’s str type is immutable, so every method here returns a new string
rather than changing the original. The methods cover case conversion, searching,
splitting and joining, trimming, testing, and encoding. This is a searchable
offline reference.
How it works
Each method lists its signature and return type. Because strings are immutable, a
call like s.upper() produces a new string — you must assign it (s = s.upper())
to keep the result. The groups are:
- Case —
upper,lower,title,capitalize,casefold,swapcase. - Search —
find,index,count,startswith,endswith.findreturns-1on failure;indexraisesValueError. - Split / join —
split,rsplit,splitlines,partition,join. - Trim / pad —
strip,lstrip,rstrip,removeprefix,removesuffix,center,ljust,rjust,zfill. - Test —
isalpha,isdigit,isalnum,isspace,isidentifier, etc. - Transform —
replace,translate,format,format_map,encode.
Example
" Hello, World ".strip().lower().replace(",", "")
# -> 'hello world'
"file.tar.gz".removesuffix(".gz") # -> 'file.tar'
Note strip('.py') would remove any trailing ., p, or y character — use
removesuffix('.py') to drop the exact substring once.
Notes
strip/lstrip/rstriptake a set of characters, not a prefix — useremoveprefix/removesuffix(Python 3.9+) for exact substrings.str.joinis called on the separator:", ".join(items).- This reference covers the standard
strmethods. For exact version availability consult the official Python docs.