A character is an individual textual element in a string, such as one alphabetic symbol. Python strings can be traversed character by character, but they cannot be modified in place. section 8.1
Character handling supports several practical tasks:
- Iterate through a string with a for loop and build a new string from its characters. section 8.1
- Create a list of individual characters with list(str), as with list('aeiou'). section 8.3.1
- Compare or sort characters with attention to case: uppercase and lowercase letters have different ASCII ordinal values. section 18.3.2
- Normalize comparisons with str.casefold, passed as a function rather than called immediately. section 18.3.2
Uppercasing characters without mutation
Given text = 'The quick brown fox jumps over the lazy dog.', assigning text[2] = 'i' raises a TypeError because strings do not support item assignment. Instead, start with new = '' and append char.upper() for each character; the resulting string is uppercase. section 8.1
>>> text[2] = 'i' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment
The failing item-assignment example makes string immutability concrete before the replacement loop is introduced. section 8.1

