7.04
Completed
Python List Slicing Python List Slicing

Learn to select parts of Python lists with start and stop indexes, omitted bounds, and negative indexing.

Python List Slicing

Sounds useful?

Jump into the interactive version.

No setup. No account. Just Python.

Interactive Python lesson

List Slicing in Python

A list can hold plenty of items, but sometimes you only need the first three, the last two, or a section from the middle. This Block shows you how to select those sections with list slicing. You will see how start and stop bounds work, why the stop index is excluded, and how omitted or negative bounds keep common slices short and readable.

What you will learn:

  • Use items[start:stop] to select a range of list items
  • Understand included start indexes and excluded stop indexes
  • Use omitted bounds for slices from the beginning or through the end
  • Select the last items with negative indexes such as items[-2:]
  • Tell the difference between indexing one item and slicing a list
  • Understand empty slices, faraway bounds, and why slicing leaves the original list unchanged

By the end, you will be able to pull useful sections from lists with short, readable Python code.

> Start now 101 cards · about 7 min

Ready to practice this in the browser?

> Play now