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 path4
lessons
31
practice questions
31
prerequisite lessons
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
Editor Output
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 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
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
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
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.
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
Builds on: Basic data types, Comparisons, Lists, Tuples
Leads to: Comprehensions, Lists, NumPy, Tuples, User-defined functions
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