The Python string methods cheatsheet is a complete quick reference for every built-in method on the str type. Each entry shows the method signature, return type, a practical copy-paste example with output, and a one-click copy button — so you spend less time searching the docs and more time writing Python.
No methods found
Try a different search term or select a different category
How to Use This Python String Methods Cheatsheet
This interactive Python string methods reference puts every built-in str method at your fingertips. Whether you are looking up the signature for replace(), checking what partition() returns, or comparing isdigit() vs isnumeric(), you can find the answer instantly without leaving your editor.
Searching for Methods
Type any keyword into the search bar to instantly filter methods. You can search by method name (e.g., strip), by a concept (e.g., "whitespace"), or by a term that appears in the example code (e.g., "split"). Results update live as you type. Click Clear or delete the text to return to the full list.
Filtering by Category
Use the category tabs to focus on a specific group of methods. Case covers conversions like upper, lower, title, and casefold. Search covers find, index, count, startswith, and endswith. Testing covers all the is* predicates like isalpha, isdigit, and isspace. Modification covers strip, replace, translate, zfill, and expandtabs. Split & Join covers split, join, partition, and splitlines. Alignment covers center, ljust, and rjust. Encoding & Format covers encode, format, and format_map.
Understanding the Method Cards
Each card shows four pieces of information. The signature block shows the method name and its parameters — positional parameters are shown by name and optional parameters include default values. The Returns line tells you the type the method gives back. The Example block shows a short, realistic Python snippet you can run or paste directly. The Copy button copies the full example to your clipboard.
Strings Are Immutable in Python
A key fact about all Python string methods: they never modify the original string. Python strings are immutable, so every method returns a new string value. You must assign the result back to a variable — for example, text = text.strip() — otherwise the return value is discarded and nothing changes. This is a common source of bugs for newcomers to Python.
Copying Code Examples
Every method card has a Copy button at the top right. Click it to copy the full code example to your clipboard, then paste it into your Python REPL, Jupyter notebook, or script. The button briefly shows "Copied!" to confirm the action, then resets automatically.
Frequently Asked Questions
Is this Python string methods cheatsheet free?
Yes, completely free with no signup, no account, and no payment required. All method references, signatures, examples, and copy buttons are available instantly in your browser.
Is my data safe when using this cheatsheet?
Absolutely. This cheatsheet runs entirely in your browser. Nothing is collected, stored, or transmitted anywhere — it works even without an internet connection after the first load.
What is the difference between find() and index() in Python?
Both search for a substring within a string, but they differ in what happens when the substring is not found. find() returns -1 if the substring is absent. index() raises a ValueError exception. Use find() when absence is expected and you want to check the result, and use index() when you are confident the substring exists.
What is the difference between strip(), lstrip(), and rstrip()?
strip() removes leading and trailing whitespace (or specified characters) from both ends of the string. lstrip() removes only from the left (start) side. rstrip() removes only from the right (end) side. All three return a new string and do not modify the original.
What is the difference between split() and partition()?
split() divides a string into a list of substrings at every occurrence of the separator, discarding the separator. partition() splits at only the first occurrence and returns a 3-tuple of (before, separator, after), always preserving the separator. Use partition() when you need to know whether the separator was found and where.
What does casefold() do and how is it different from lower()?
casefold() is a more aggressive lowercase conversion designed for case-insensitive string matching across different languages. For example, the German sharp-s 'ß' becomes 'ss' with casefold() but stays 'ß' with lower(). For comparing strings in a case-insensitive way, prefer casefold() over lower().
Are Python string methods destructive? Do they change the original string?
No. Python strings are immutable — no string method modifies the original string. Every method returns a new string value. You must assign the result to a variable (e.g., s = s.strip()) to keep the change.
What is the difference between isdigit(), isnumeric(), and isdecimal()?
isdecimal() is the strictest — it returns True only for decimal digits 0-9 that can form decimal numbers. isdigit() also accepts superscript digits and digit-like Unicode characters. isnumeric() is the broadest, also accepting fractions, Roman numerals, and other numeric Unicode characters. For validating plain integer input, use isdecimal().