Strings and lists

Working with sequences of characters and sequences of values, and how Python's references behave.

About 8 hours of study

Learning objectives

Lessons

  1. 1

    Working with strings

    Index, slice and loop over text, and use string methods such as upper() and replace().

  2. 2

    Lists

    Store many values in one list, change it, loop over it, and see why two names can share one list.

  3. 3

    enumerate and zip

    Loop with a counter using enumerate, and walk through two lists side by side with zip.

  4. 4

    Lists of lists

    Store tables and game boards as nested lists, and avoid the trap of copying a row.

Module practice

Module quiz

1. What is "banana"[1:4]?
2. s = "hello"; s[0] = "H". What happens?
3. a = [1, 2]; b = a; b[0] = 9. What is a?
4. What does list(zip([1, 2], ["a", "b"])) give?
5. Why should a grid not be made with [[0] * 3] * 3?
6. Which is the best way to get both the position and the value in a loop?

‹ Decisions and loopsFunctions and modules ›