String methods return new strings or answers about text because strings are immutable.
Most text work starts with cleaning whitespace, normalizing case, splitting input, or joining output.
Choose the method by the job: clean, search, split, join, validate, or format.
strip(), lower(), upper(), and replace() are common cleanup methods.
name = " maya sharma "
clean_name = name.strip().title()
print(clean_name)
Maya Sharma
strip() removes outside spaces, and title() formats the words for display.
find(), in, startswith(), and endswith() help test whether text contains a pattern.
split() turns text into a list. join() turns a list of strings into text.
raw_tags = "python, data, automation"
tags = [tag.strip() for tag in raw_tags.split(",")]
slug = "-".join(tags)
print(tags)
print(slug)
['python', 'data', 'automation']
python-data-automation
split() creates pieces, strip() cleans each piece, and join() combines them with hyphens.
Methods such as isdigit(), isalpha(), and isidentifier() answer questions about text shape.
Try this next
0 of 3 completed
Strings are immutable. Store the returned string, such as text = text.replace("old", "new").
No. Use string methods first when the rule is simple. Regex is better for patterns.
split() breaks text into a list. join() combines a list of strings into one string.
Explore 500+ free tutorials across 20+ languages and frameworks.