Skip to main content
Module 4 · Lesson 1 of 413/36 in the course~16 min
Module lessons (1/4)

String methods

Lesson preview5 hands-on exercises readyPython Course · Module 4 — Strings and numbers

Everyday methods: upper/lower, strip, split/join, replace, startswith/endswith, find, and in.

What you'll learn in this lesson

  • Manipulate strings with the most used built-in methods (.strip(), .split(), .join(), .replace()).
  • Remember the immutability of strings: each method returns a new string and requires reassignment (s = s.upper()).
  • Search for substrings safely by choosing between in, .find() (-1 if absent) and .startswith()/.endswith().

Overview

strings (str) in Python are immutable sequences of Unicode characters. This means that no method ever modifies the existing string in memory: each call creates and returns a new string object, leaving the original unchanged unless you save the return value.

When you chain raw_text.strip().lower(), you are building a short transformation pipeline where each step allocates a new temporary string without mutating raw_text. It is a very safe style for cleaning dirty input coming from users, CSV or API.

Sections covered in this lesson

  1. 1The mental model: pure transformations with explicit reassignment
  2. 2Safe cleaning, normalization and concatenation
  3. 3Split (split), merge (join) and inspect contents
  4. 4Quick check
  5. 5Test yourself
Pro Lesson · Module 4 — Strings and numbers

Unlock "String methods" and the full Python Course curriculum

Everyday methods: upper/lower, strip, split/join, replace, startswith/endswith, find, and in.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Python Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.