Python theorytheory 0/50 · 0%
Types · easy

4. Strings

Immutable text sequences with rich formatting.

Strings are immutable sequences of Unicode code points. Slicing, concatenation and formatting are frequent operations.

python
s = "Blockchain"
s[0:5]        # "Block"
s[::-1]       # reversed
s.upper()
f"{s} has {len(s)} chars"

f-strings (`f"..."`) are the modern way to interpolate values and support format specs like `f"{value:.2f}"` for two decimal places.

Because strings are immutable, methods like `.replace()` or `.upper()` return new strings rather than mutating in place.

Check your understanding

  1. 1. Are Python strings mutable?

  2. 2. What does `s[::-1]` produce?

  3. 3. Which literal syntax embeds expressions directly?