Lists
A list is a row of items in order.
Think of toys lined up on a shelf.
You can add a toy, remove a toy, or swap one.
Lists use square brackets and commas.
Creating a list
Put items between [ and ].
Items can be text, numbers, or even other lists.
len() counts how many items you have.
Indexing
Each item has a place number.
The first item is at 0.
Negative indexes count from the end.
Slicing
A slice takes a piece of the list.
Write [start:end]. The end place is not included.
nums[1:4] takes indexes 1, 2, and 3
nums[:2] takes from the start
nums[2:] takes to the end
nums[:] copies the whole list
Changing items
Lists can change.
Assign a new value to an index.
Like replacing one toy on the shelf.
Nested lists
A list can hold other lists.
Like a box that holds smaller boxes.
Use two indexes: first pick the inner list, then pick the item.
Looping through a list
A for loop visits each item one by one.
Like walking down the shelf and naming each toy.
Tip: Use lists when order matters and you need to change the collection later.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.