1. Concept library
  2. Python Foundations
  3. Module 4: Lists and tuples

Concept

Indexing and slicing

Square brackets pick one item by position, counting from zero and from the end with negatives. A slice start:stop:step copies a part of the sequence without changing it.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain how positive and negative indexes count positions
  2. Predict the result of slices with start, stop and step, including omitted parts
  3. Spot an off-by-one error from treating the stop index as inclusive

In practice

A few lines that show Indexing and slicing doing its job.

Python
days = ["mon", "tue", "wed", "thu", "fri"]

print(days[0], days[-1])     # mon fri
print(days[1:3])             # ['tue', 'wed']
print(days[:2], days[3:])    # ['mon', 'tue'] ['thu', 'fri']
print(days[::-1])            # reversed copy

The common mistake

Watch for

Treating the stop index as inclusive. days[1:3] gives two items, positions 1 and 2. The stop is the first position left out.

What to know first

Your roadmap puts these before Indexing and slicing, unless you already know them.

How it stays learned

Once a session shows you understand Indexing and slicing, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Indexing and slicing.

Next in the moduleList methods →