Back
+10 XP
Concept

Strings Cannot Be Changed (Immutability)

Strings are **immutable** (incapable of change). Once created, you cannot swap individual letters:

python
pet = "Dog"
pet[0] = "F"  # CRASH! TypeError: 'str' object does not support item assignment

# 34. Strings Cannot Be Changed (Immutability) Strings are **immutable** (incapable of change). Once created, you cannot swap individual letters: ```python pet = "Dog" pet[0] = "F" # CRASH! TypeError: 'str' object does not support item assignment ``` Want `"Fog"`? You have to assemble a brand-new string: `pet = "F" + pet[1:]`.

Checkpoint

Why does `word[0] = "X"` fail on strings?

Practice

You have `pet = "Cat"`. Create `"Bat"` by taking `"B"` and adding the sliced tail `pet[1:]`. Print the result.

Terminal
01
Tap code blocks below to assemble
Available Blocks