Python's immutable sequence: writing tuple literals, indexing and slicing them as with lists, and why immutability does not reach the mutable objects stored inside.
No account needed to read a lesson · 30-day money-back guarantee
See the full learning path4
lessons
19
practice questions
25
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:
3 (4, 5)
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
Tuples
6 questions
Understand what makes a tuple distinct from a list in Python and learn how to correctly create tuples of any size using literal values, including cases with no elements or only one element.
Covers
Tuple overview
Creating a tuple using literal values
02
Tuple indexing, length and slicing
4 questions
Learn how to access individual elements in a tuple using indexing, determine its length with len(), and retrieve subsets of elements through slicing, using the same syntax as with lists.
Covers
Tuple indexing, length and slicing
03
Tuple immutability
4 questions
Understand that while tuples in Python are immutable containers whose elements cannot be changed, added, or removed, the contents of mutable objects stored within a tuple can still be modified, which can lead to unexpected side effects.
Covers
Tuple immutability
04
Activity: travel itinerary builder
5 questions
Develop a Python program that allows users to build, update and customise a travel itinerary by adding destinations, activities and planning short trips.
Covers
Create itinerary
Get destination and activity
Add activities
Understand tuple mutability
Plan short-trips
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
25 prerequisite lessons across the unit, counting every step back to the start
71 other lessons in the learning path - after this unit, or alongside it
Builds on: Comparisons, Lists, Sequences
Leads to: Dictionaries, Lists, Loops, Sequences, 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 Data structures: Lists, Dictionaries, Sets