Python Strings

Slice, split, join, and format text efficiently.

  • python strings
  • split join
  • f-string
  • strip
  • format

Python Strings

Slice, split, join, and format text efficiently.

Commands

CommandWhat it does
s.strip().lower()Trim and normalize case
split on commaTurn a,b into a list
join with comma-spaceTurn a list into text
Hi-name format callstr.format style
text.removeprefix prefixDrop a known prefix (3.9+)

Example

raw = "  Ada,Lovelace  "
parts = [p.strip() for p in raw.split(",")]
print(" ".join(parts))  # Ada Lovelace

FAQ

f-string vs .format vs %?

f-strings are fastest to read and write; .format suits templates stored separately; % is legacy.

How do I handle unicode?

Python 3 strings are unicode by default; open files with encoding="utf-8" explicitly.

자주 묻는 질문

f-string vs .format vs %?
f-strings are fastest to read and write; .format suits templates stored separately; % is legacy.
How do I handle unicode?
Python 3 strings are unicode by default; open files with encoding="utf-8" explicitly.

Python