String Methods in Python

StringsString Formatting

Strings come with many built-in methods that help you manipulate and check text. These methods return new strings – they don't change the original (strings are immutable).

We'll go through the most common ones with explanations and examples you can run right away.

Changing Case

These methods convert the string to uppercase, lowercase, title case (first letter of each word capitalized), or capitalize the first letter.

Trimming Whitespace

strip() removes whitespace from both ends, lstrip() from the left, and rstrip() from the right. This is useful when cleaning user input.

Replacing Text

replace() substitutes text. By default it replaces all occurrences, but you can limit the number of replacements.

Splitting and Joining

split() turns a string into a list by separating at a delimiter (default is whitespace). join() does the opposite – combines a list into a string using a separator.

Checking Content

These methods return True or False to check if a string starts/ends with something or contains only certain characters.

Finding Positions

find() returns the index of the first occurrence or -1 if not found. index() does the same but raises ValueError if not found.

Quick Quiz

We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.

✨ Ask Lara — your AI study partner

Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.


Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.