By the end of this lesson
Read, append and safely copy a short collection.
Before you start
- Python 3.12 or a compatible newer Python 3 interpreter; no external packages.
- Complete lesson 6 in this route, or be comfortable with its examples.
Three words to know
- List
- An ordered, mutable collection.
- Tuple
- An ordered collection whose own item references cannot be reassigned.
- Alias
- A second name referring to the same object.
1. Read and extend a list
Lists preserve order and allow duplicates. Indexing starts at zero. append changes the existing list and returns None; do not assign its result back to the list. An empty list has no first element, so check before indexing.
topics = ["terminal", "python"]
topics.append("json")
print(topics[0])
print(len(topics))
print(topics[-1])
What you should see · example output
terminal 3 json
2. Assignment is not a copy
Both names below initially refer to the same list. A shallow copy creates a new outer list. It does not recursively copy nested lists or other mutable values; that distinction matters when your data gets more complex.
original = ["a"]
alias = original
independent = original.copy()
alias.append("b")
print(original)
print(independent)
What you should see · example output
['a', 'b'] ['a']
3. Group fixed positions with a tuple
A tuple is useful for a short record whose positions have agreed meanings. Unpacking gives each position a readable name. For larger records, a dictionary or a named data class can be clearer. Tuple immutability does not make an embedded list immutable.
result = ("open", 2)
status, count = result
print(f"{status}: {count}")
What you should see · example output
open: 2
YOUR TURN
A small check before you continue
Create a copy of [1, 2], append 3 only to the copy, and print both lists.
Show a suggested answer
Use copy = original.copy(), then copy.append(3). The original stays [1, 2] and the copy is [1, 2, 3]. Avoid naming the variable list because that would hide the built-in.
Sources and scope
Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.
