Python · live now

Sequences

What lists, tuples and strings have in common: slicing with a start, stop and step, and unpacking a sequence into separate variables in one statement.

No account needed to read a lesson · 30-day money-back guarantee

See the full learning path

4

lessons

31

practice questions

31

prerequisite lessons

See it taught

1 of the 4 lessons here is free to preview - the whole explanation and worked example, with no account and no email.

The editor you get

A still of the editor, not a live one

Python Editor

1 2
nums = [0, 1, 2, 3, 4, 5] print(nums[1:5], nums[::2])

Editor Output

1

Output:

[1, 2, 3, 4] [0, 2, 4]

You write and run Python in the browser - nothing to install, no setup. Questions are marked on the values your code produces. The snippet here is an example of the kind of code you write.

The 4 lessons

The 4 lessons in this unit. Expand any one to see what it covers. Each unlocks when its own prerequisites are passed.

01

Sequences

8 questions

Understand what defines a sequence in Python, including how to measure its length, access elements using zero-based and negative indexing, and distinguish between homogeneous and heterogeneous types.

Covers

Introduction to sequences

Indexing sequences

02

Slicing sequences

Preview

13 questions

Learn how to extract subsequences from lists, tuples or strings in Python using the slicing syntax with different start and stop indices, creating new sequences without modifying the originals.

Covers

Introduction to sequence slicing

Slicing a list and tuple

Slicing a string

Preview this lesson - no account needed

03

Slicing sequences with a step

6 questions

Learn how to use Python sequence slicing with a step value to select elements at fixed intervals or in reverse order.

Covers

Slicing with a step

Slicing with a negative step

04

Unpacking sequences

4 questions

Learn how to assign multiple variables at once by unpacking the elements of a sequence such as a tuple, list or string directly in Python.

Covers

Unpacking sequences

Where this unit sits in the curriculum

This unit is part of our Python Done Right learning path, which contains 100 lessons. Every one of them is drawn below.

The diagnostic test lets you skip any lesson you already know, including the ones in this unit.

Every dot is a lesson and every line a prerequisite. The 4 red dots are the lessons in Sequences; the 31 blue dots feeding into them are the lessons Sequences depends on; the 65 pale dots are the rest of the learning path, which come after Sequences or alongside it.SequencesFirst lessons on the left100 lessons

Hover any dot to name its lesson.

4 lessons in this unit

31 prerequisite lessons across the unit, counting every step back to the start

65 other lessons in the learning path - after this unit, or alongside it

Every dot is a lesson, every line a prerequisite. You can only start a lesson once you have mastered all of its prerequisites, so you are always building on solid foundations.

Start Sequences

One subscription covers every learning path, and you can test out of anything you already know.

One subscription covers every learning path · 30-day money-back guarantee

More in Iteration: Loops, Comprehensions