liveBook · Manning

Character

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

An individual textual element in a string, specifically an alphabetic symbol in this exercise.

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

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Explains iteration, immutability, construction of replacement strings, and ASCII ordering, but does not descend into character encoding internals.
Examples
Demonstrates uppercase conversion, vowel substitution, vowel-choice validation, case-sensitive sorting, and case-insensitive sorting.
What it assumes
Assumes familiarity with strings, for loops, dictionaries, and basic command-line argument validation.
What you can do after
Apply character iteration and case handling to construct transformed strings and perform reliable text comparisons.
How it connects
Connects characters with strings, for loops, list comprehensions, string replacement, ASCII, regular expressions, and case-insensitive comparison.

Also explained in

Compare how 2 books explain character →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.