Sponsored Reserved space — layout preview until AdSense is connected

Reference

Python string methods — a quick reference

The string methods you reach for most often, grouped by what they do, with one-line examples.

May 2026 · 6 min read · 1 views · 0 hearts

Cleaning

  • .strip() / .lstrip() / .rstrip() — remove surrounding whitespace.
  • .replace(old, new) — swap substrings.

Casing

  • .lower(), .upper(), .title(), .capitalize().
  • .casefold() — aggressive lowercasing for comparisons.

Searching and testing

  • .startswith() / .endswith() — boolean checks.
  • .find() vs .index() — find returns -1, index raises.
  • .count(sub) — how many times it appears.

Splitting and joining

",".join(["a", "b", "c"])   # 'a,b,c'
"a,b,c".split(",")          # ['a', 'b', 'c']

Strings are immutable, so every method returns a new string rather than changing the original.

Comments

Questions, corrections, and tips stay visible for everyone reading this page.

0 in thread

Join the discussion

Shown next to your comment.

Constructive tone · up to 4,000 characters

No comments yet

Be the first to leave a note — it helps the next reader.

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected