A string is an immutable sequence of characters: indexable, iterable, sliceable — but never editable in place.
1 Immutable
s[0] = "X" raises TypeError. Every “change” — upper(), strip(), + — builds a brand-new string object.
2 Index and slice
s[0] is the first char, s[-1] the last, s[::-1] the whole string reversed. len(s) is O(1).
3 Iterate directly
for ch in s hands you characters one by one — no index bookkeeping needed for most scans.
4 Membership
ch in "aeiou" is a clean membership test; "cat" in "catalogue" finds substrings too.
5 F-strings
f"{name} has {len(name)} letters" — {} slots run real Python expressions, right inside the text.
Text as a sequence
Immutable1s[0] = "X" raises TypeError. Every “change” — upper(), strip(), + — builds a brand-new string object. Index and slice2s[0] is the first char, s[-1] the last, s[::-1] the whole string reversed. len(s) is O(1). Iterate directly3for ch in s hands you characters one by one — no index bookkeeping needed for most scans. Membership4ch in "aeiou" is a clean membership test; "cat" in "catalogue" finds substrings too. F-strings5f"{name} has {len(name)} letters" — {} slots run real Python expressions, right inside the text.
5 building blocks make up Text as a sequence
Two pointers squeeze racecar from both ends — and bail out instantly on python.
1 / 8Is "racecar" a palindrome? left starts at index 0, right at index 6.
Strings cannot edit themselves — every transformation is build-a-new-object, then rebind.
A vowel counter over beautiful, then a username pipeline that chains three string methods.
moduleNine characters to scan.
Console
output appears as the program runs…
Scan beautiful letter by letter and fill the a-e-i-o-u table as vowels appear.
1 / 11Scanning "beautiful" — the table counts a, e, i, o, u as they appear. All zeros so far.
Slices, reversal and the palindrome trick in six lines.
Your predicted output — one line per console line
Hint: s[::-1] walks the whole string backwards. == compares content, and len counts characters.
Click a term, then click its meaning to lock the pair.
8 conceptsTap a card to expand ?immutabledrops into place
?s[::-1]drops into place
?f"{name}!"drops into place
?len(s)drops into place
?ch in "aeiou"drops into place
?s.strip()drops into place
?+ joinsdrops into place
?s[i]drops into place
01Strings are immutable: every “change” builds a new object and the name rebinds.
02for ch in s walks characters directly — no index bookkeeping needed.
03ch in "aeiou" is the cleanest vowel test; the same membership works for substrings.
04s[::-1] reverses; s == s[::-1] is the one-line palindrome check.
05F-strings interpolate any expression: f"{len(s)} chars".
06Method chains read left to right: raw.strip().lower().replace(" ", "_") — each step a new string.