~/learn/Python · Text & files

String methods

Split, join, strip and reshape text.

7 min readlesson 13 of 23splitjoinformat

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.

python · editable
loading editor…

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.

python · editable
loading editor…

f-strings format values inline, including alignment and rounding, which keeps printed output readable.

python · editable
loading editor…

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.