~/learn/Python · Text & files
String methods
Split, join, strip and reshape text.
why this matters
Names, emails, log lines — text is everywhere, and cleaning it is a daily task.
Strings are immutable: every method returns a new string. split and join are the pair you reach for most — one turns text into a list, the other turns a list back into text.
Try it: Title-case every name before joining them.
Tests and cleanup: startswith, endswith, in, replace, removeprefix and the case helpers. Compare case-insensitively by lowering both sides.
f-strings format values inline, including alignment and rounding, which keeps printed output readable.
key takeaways
- .strip(), .lower(), .split() are the workhorses.
- Strings can't be changed — methods return new ones.
- ", ".join(items) glues a list together.
check your understanding
s = " Hi ". After s.strip(), what is s?
free practice
Build confidence with a question you can solve without Pro.