Module lessons (1/4)
String methods
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()(-1if 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
- 1The mental model: pure transformations with explicit reassignment
- 2Safe cleaning, normalization and concatenation
- 3Split (
split), merge (join) and inspect contents - 4Quick check
- 5Test yourself
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.