Drop links or images here to add them to the editor.

In this topic students learn to take strings apart and build new ones: measuring them, changing their case, slicing out substrings, looping over their characters and converting between characters and ASCII codes.

Learning objectives and goals

Be able to read, comprehend, trace, adapt and create Python code that:

Slide deck

This chapter was written for Dodona from new material by the course author, after the rest of the course had been converted, so it has no deck of its own. The author’s Intermediate Python series has a String manipulation deck that covers the same topic with different examples: on Google Slides. A PDF copy is kept on Dodona too.

Teacher notes

This chapter comes after Lists and leans on it throughout. A string is indexed the same way a list is, from zero, with square brackets, and len does the same job on both. Students who are secure on list indexing usually find single characters easy; the new idea is the slice, where two numbers pick out a whole stretch.

The chapter is split into four short theory pages rather than one: length and case, substrings, looping through a string, and ASCII codes. The course author’s code-snippets table closes the last of them as a summary. Two of those pages teach constructs that the author’s tasks need but the snippets table does not list: iterating over a string (Make 2 and Make 3) and nested loops (Make 3).

Later chapters rely on this one: 2D arrays uses upper() and file handling uses lower().

Key points

Errors and misconceptions