Computer 2

Thursday, February 19, 2026

Twine Quiz and Python Lists

Agenda

  1. Twine quiz
  2. Learn about Python lists by watching video and reading this page.
  3. Work on a Lists worksheet in class and for homework. It is due by the end of class on Monday, February 23, 2026.

Twine Quiz

When it is time to take the quiz, the Quiz Code will be written on the board. Enter the quiz code in the text field below and click "Submit".

Introduction to Python Lists

Store, access, and change collections of data.

Python Lists Video

Watch this video to learn about Python lists.

What Is a List?

A list is a Python data type that holds multiple items in a single variable. Items are ordered, changeable, and accessed by their position number (called an index).

# Creating lists
team = ["Marcus", "Jake", "Deon", "Luis"]
scores = [98, 85, 72, 100]
empty = []

Lists use square brackets [ ] and items are separated by commas. A list can hold strings, numbers, booleans, or a mix of types.

Accessing Items by Index

Every item has an index. Indexing starts at 0, not 1.

index 0"Marcus"
index 1"Jake"
index 2"Deon"
index 3"Luis"
team = ["Marcus", "Jake", "Deon", "Luis"]

print(team[0])    # Marcus
print(team[2])    # Deon
print(team[-1])   # Luis  (last item)
Watch out! Using an index that doesn't exist (like team[4] in a 4-item list) causes an IndexError. The last valid index is always len(list) - 1.

Changing, Adding, and Removing Items

Lists are mutable — you can modify them after creation.

Change an item

team[1] = "Jordan"
# team is now ["Marcus", "Jordan", "Deon", "Luis"]

Add to the end

team.append("Kai")
# team is now ["Marcus", "Jordan", "Deon", "Luis", "Kai"]

Insert at a position

team.insert(2, "Tyler")
# Puts "Tyler" at index 2, shifts the rest right

Remove by value

team.remove("Deon")
# Removes the first occurrence of "Deon"

Remove by index

team.pop(1)   # Removes item at index 1
team.pop()    # Removes the last item

Useful Operations

Code What It Does
len(team) Returns how many items are in the list
"Marcus" in team Returns True if "Marcus" is in the list
team.sort() Sorts the list in place (alphabetical or numerical)
team.reverse() Reverses the order of items
team.count("Jake") Counts how many times "Jake" appears
team.index("Deon") Returns the index of the first "Deon"
team.clear() Removes all items from the list

Looping Through a List

Use a for loop to do something with every item in a list:

for player in team:
    print(player + " is ready!")

The loop variable (player) takes on each value in the list, one at a time, from first to last.

Quick Reference

Syntax Meaning
my_list = [a, b, c] Create a list with items a, b, c
my_list[i] Get item at index i (starts at 0)
my_list[-1] Get the last item
my_list[i] = x Change item at index i to x
my_list.append(x) Add x to the end
my_list.insert(i, x) Insert x at index i
my_list.remove(x) Remove first occurrence of x
my_list.pop(i) Remove & return item at index i
len(my_list) Number of items
x in my_list Check if x exists in list
for item in my_list: Loop through every item