Chapter 019 / 132 · Level 1 · Beginner Python textbook

Lists and tuples: several values together

Complete Python PDF
Checking PDF availability…

Chapter 19 of 132 · Level 1 · Beginner Python textbook · 7 real coding demonstrations + 2 worked code answers. Learn through reading, predicting and testing real Python code.

Code + real outputPractice + explanationsOffline Python exercises
Course disclaimer · independent educational content
EasyTutorGuide creates independent educational tutorials. Python and other product names remain the property of their owners; this course is not endorsed by the Python Software Foundation or third-party providers. Examples are for learning and should be reviewed and tested before production use. Do not expose real API keys or private data. Translation is automated and may introduce errors; code examples remain untranslated. Terms · Privacy · Legal.
01 · Start here: simple explanation

Store multiple related values together so you can process them with one loop.

A list stores values in a particular order and can be changed. Place items between square brackets, separated by commas. Lists can contain duplicates.

Use indexing to get one item and slicing to get several. Similar to strings, a list begins at index 0. Lists can grow through append and change by assigning to an index.

Sorting with sorted(items) returns a new sorted list. items.sort() changes the original list. This distinction between returning a new value and changing an existing object is important.

A tuple is also ordered, but you cannot replace its elements. Parentheses are common when writing tuples. Tuples are useful for a small fixed record such as width and height.

02 · Learning objectives and technical words

By the end you can…

  • Create and inspect lists
  • Add, remove, and sort values
  • Understand the role of immutable tuples

Words you should know

list
an ordered, mutable collection
tuple
an ordered, immutable collection
append
add a value to the end of a list
mutation
changing an existing object
03 · Point-by-point: understand the idea
PINPOINT LEARNING

Locate the input, identify the Python instruction that changes it, and compare the printed result. Make a prediction before each run so you understand what the program does—not only how to copy it.

Do not call print(items.append("new")) expecting the updated list; append changes the list and returns None. First append, then print the list.

04 · Coding examples with real outputs

Example 1: Create and read a list

Python · runnable
PYTHON CODE
fruits = ["apple", "pear", "plum"]
print(fruits[0])
print(fruits[-1])
Verified execution ▼
apple
plum

Why it works: A list has the same zero-based indexing rule as a string.

Example 2: Add an item

Python · runnable
PYTHON CODE
tasks = ["study", "walk"]
tasks.append("read")
print(tasks)
Verified execution ▼
['study', 'walk', 'read']

Why it works: append changes the existing list and adds one value.

Example 3: Change one item

Python · runnable
PYTHON CODE
colors = ["red", "blue"]
colors[1] = "green"
print(colors)
Verified execution ▼
['red', 'green']

Why it works: Lists are mutable: an indexed element can be replaced.

Example 4: Take a slice

Python · runnable
PYTHON CODE
numbers = [10, 20, 30, 40]
print(numbers[1:3])
Verified execution ▼
[20, 30]

Why it works: The slice returns elements at indexes 1 and 2, not 3.

Example 5: Sorted copy vs original

Python · runnable
PYTHON CODE
scores = [8, 3, 6]
ordered = sorted(scores)
print(ordered)
print(scores)
Verified execution ▼
[3, 6, 8]
[8, 3, 6]

Why it works: sorted leaves scores alone and creates an ordered copy.

Example 6: Remove a known value

Python · runnable
PYTHON CODE
shopping = ["milk", "bread", "eggs"]
shopping.remove("bread")
print(shopping)
Verified execution ▼
['milk', 'eggs']

Why it works: remove deletes the first matching value. It raises an error if the value is missing.

Example 7: Use a tuple for coordinates

Python · runnable
PYTHON CODE
point = (3, 7)
x, y = point
print("X:", x)
print("Y:", y)
Verified execution ▼
X: 3
Y: 7

Why it works: Tuple unpacking assigns the two elements to descriptive names.

05 · Exercises, debugging and worked answers

Try without looking

  1. Create a list of three favorite foods and print the second food.
  2. Add "tea" to a drinks list and print the length.
  3. Explain why tuple values should not be assigned using an index.

Worked answers

Worked solution 1: Worked answer: second food

Python · runnable
PYTHON CODE
foods = ["rice", "soup", "salad"]
print(foods[1])
Verified execution ▼
soup

Why it works: The second item is at index 1.

Worked solution 2: Worked answer: append and length

Python · runnable
PYTHON CODE
drinks = ["water", "juice"]
drinks.append("tea")
print(len(drinks))
Verified execution ▼
3

Why it works: len reports the number of items after adding tea.

06 · Build a mini-project and review

Mini-build: A simple reading list that displays numbered book titles and marks one entry as completed.

Progress check

Can you explain the output before running the code? Can you change the inputs without breaking the program? Revisit the examples until you can do both.