OpenViSTAI · Agents · Blockchain · Crypto
Menu

OPENVIST LEARN · FREE LESSONS

Lists, tuples and shared values

Keep related values together and see the difference between changing a list and copying it.

Lesson 7 of 22 · About 20 minutes · Beginner · English

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.

Track completed topicsPYTHON · save as lesson.py, then run with your interpreter
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.

Compare an alias with a copyPYTHON · save as lesson.py, then run with your interpreter
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.

Unpack a pairPYTHON · save as lesson.py, then run with your interpreter
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.