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
| Command | What it does |
|---|---|
s.strip().lower() | Trim and normalize case |
split on comma | Turn a,b into a list |
join with comma-space | Turn a list into text |
Hi-name format call | str.format style |
text.removeprefix prefix | Drop 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.
Perguntas frequentes
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
Python Venv and Environments
Isolate dependencies per project with venv and pinned requirements.
Python Pip Essentials
Install, upgrade, and audit packages with pip like a pro.
Python Basics
Syntax survival kit: variables, loops, f-strings, and errors.
Python Lists
Comprehensions, slicing, sorting, and friends for sequences.