String Manipulation

Lesson 9 of 20

Slice, clean and combine text with string methods and f-strings — Python makes words easy to program.

The big picture

Text is data too

Strings are sequences of characters — Python gives you dozens of methods plus f-strings to bend them.

Sequences of Chars

Index and slice them like lists: s[0] is the first character, s[1:3] a mini-string.

Methods Transform

upper(), lower(), strip() and replace() each return a NEW string.

Immutability

A string never changes in place — every method hands you a modified copy.

f-strings Inject

f"Hi {name}" evaluates the braces and builds the final text for you.