Part 2 · Section 02

Sequences

Lists, tuples, strings and ranges look different, but they share one idea: their items have positions, numbered from 0. Because of that shared shape, they all support the same core operations (indexing, slicing, len, in, concatenation), and once you know the protocol behind those operations you can make your own classes behave exactly like built-in sequences.

This section also digs into the details that trip people up in real code: shallow vs deep copies, why += on a list is not the same as +, what happens when you assign to a slice, and why a list of lambdas built in a loop all return the same thing.

In this section you’ll learn:

Lectures

  1. 01Sequence Types✓
  2. 02Mutable Sequence Types✓
  3. 03Lists vs Tuples✓
  4. 04Copying Sequences✓
  5. 05Slicing✓
  6. 06Custom Sequences - Part 1✓
  7. 07In-Place Concatenation and Repetition✓
  8. 08Assignments in Mutable Sequences✓
  9. 09Custom Sequences - Part 2a✓
  10. 10Custom Sequences - Part 2b/c✓
  11. 11Sorting Sequences✓
  12. 12List Comprehensions✓

Practice: quiz & exercises

12 quiz questions · 4 coding exercises

Go to practice →