Python String Methods
What You’ll Find Here
Python strings ship with dozens of built-in methods for formatting text, searching substrings, validating input, and converting data. This page is your central hub: browse every essential str method, jump to full tutorials where available, and learn patterns that work in real programs.
Full Tutorials
15 methods with examples.
Quick Reference
All methods by category.
Searchable
Filter by method name.
Immutable
Methods return new values.
Beginner Tips
Usage patterns included.
Start Here
capitalize() → isdigit().
Introduction
In Python, a string (str) is a sequence of characters. You call methods on a string variable using dot notation: text.strip(), name.upper(), email.find("@"). These methods make everyday text tasks—cleaning user input, building messages, checking file extensions—fast and readable.
String methods never change the original string. Always use or assign the return value: clean = raw.strip(), not just raw.strip() alone when you need the result later.
String Methods Index
Search by method name or browse by category. Cards marked Tutorial link to full guides with examples, output, and FAQs.
Case & Formatting
10 methodsChange letter case, pad text, and align strings inside a fixed width.
First character upper, rest lower.
Aggressive lowercase for comparisons.
Center text within a width.
Return an all-lowercase copy.
Return an all-uppercase copy.
Capitalize the first letter of each word.
Swap upper- and lowercase letters.
Left-align with padding.
Right-align with padding.
Pad with leading zeros.
Search & Check
8 methodsLocate substrings, count occurrences, and test prefixes or suffixes.
Index of substring, or -1.
Index of substring, or ValueError.
Count how many times sub appears.
True if string ends with suffix.
True if string starts with prefix.
Swap one substring for another.
Last index of substring, or -1.
Last index of substring, or error.
Split, Join & Whitespace
10 methodsBreak strings apart, merge iterables, and trim extra space.
Replace tabs with spaces.
Split into a list by delimiter.
Split from the right.
Split on line boundaries.
Split into three parts once.
Partition from the right.
Join iterable with separator.
Remove leading and trailing space.
Remove leading whitespace.
Remove trailing whitespace.
Validation (is* methods)
11 methodsReturn True or False to validate character content.
Letters and digits only.
Letters only.
Strict decimal digits.
Digit characters only.
Valid Python identifier.
All cased chars are lowercase.
All cased chars are uppercase.
Title-cased words.
Whitespace characters only.
Numeric characters.
All characters printable.
Encoding & Templates
4 methodsBuild formatted messages and convert text to bytes.
Encode str to bytes.
Fill {placeholders} with values.
Format from a dictionary.
Build a translation table.
🚀 Usage Tips
- Chain methods — combine steps in one line:
user_input.strip().lower(). - Know optional parameters — many methods accept
start,end, orwidth; check each tutorial for defaults. - Handle errors — use
try/exceptwithindex(); check-1fromfind(). - Pick the right check —
isdecimal()for strict digits,isalnum()for usernames,endswith()for file types. - Read the tutorial — each linked method page includes syntax, examples, and a quick reference table.
📝 How to Call a String Method
Every string method follows the same pattern:
variable.method_name(arguments) Common Patterns
| Goal | Example |
|---|---|
| Format display text | label.capitalize() |
| Find a substring | text.find("error") |
| Build a message | "Hello, {name}".format(name="Mari") |
| Validate input | pin.isdigit() |
| Check file extension | filename.endswith(".pdf") |
Conclusion
Python string methods cover almost every text task you will encounter as a beginner—from tidying user input to searching logs and formatting output. Use this index to find the right method quickly, then open the full tutorial for syntax, examples, and best practices.
Start with capitalize() if you are new to string methods, then explore find(), format(), and the is* validation methods.
❓ Frequently Asked Questions
Tip: Python strings are immutable. Methods like upper() and replace() return a new string—they never change the original.
Start Your First String Method Tutorial
Open the capitalize() guide—syntax, five examples, and a quick reference cheat sheet.
19 people found this page helpful
