Python 3.1The video for this lesson is on its way.
Everything else is ready: study the parts, the key terms and the quiz below.
- Part 11The list we already have
- Part 22Indexing, and negative indices
- Part 33Slicing
- Part 44Changing a list: append, insert, remove and pop
- Part 55Asking questions of a list: len, sum, min, max, in, index and count
- Part 66sort and sorted
- Part 77Two names, one list: aliasing
- Part 88Copies, and rebinding against mutation
- Part 99Recap, your challenge, and tuples next
Python 3.1Code walkthrough9 parts
Lists
Store ordered, changeable collections and slice them.
Loading your progress…Next: 3.2 Tuples
In this lesson9 parts
- 01The list we already have
- 02Indexing, and negative indices
- 03Slicing
- 04Changing a list: append, insert, remove and pop
- 05Asking questions of a list: len, sum, min, max, in, index and count
- 06sort and sorted
- 07Two names, one list: aliasing
- 08Copies, and rebinding against mutation
- 09Recap, your challenge, and tuples next
Key terms
The words this lesson introduces, each in one line. The module’s glossary collects them all.
- alias
- A second name bound to the same object: after
backup = cart,backupis an alias ofcart. - element
- One value stored in a list.
- index
- An element's position, counting from zero. A negative index counts from the end, from
-1. - method
- A function that belongs to an object, called with a dot:
cart.append(...),review.lower(). - mutable
- A type whose objects can be changed after they are created; a list is mutable, and so are sets and dictionaries.
- mutation
- Changing an object in place, which every alias sees:
append,remove,sort, assigning to an index. - slice
- A range of elements, from a start up to but not including a stop, with an optional step:
temps[2:5],temps[::-1]. A slice is a new list.
Quiz 5 questions
Your first pick on each question is the one that counts, and a right one earns a coin. Getting one wrong here is how the lesson sticks.
Practice
Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.
The self-checking notebook for this lesson is Notebook 1 · Lists and Tuples.
Common mistakes
What you will see when it goes wrong, why it happens, and the fix.
Where it’s used
Where this lesson’s ideas turn up in real work.