Python Lists Foundation
list / tuple Topic 05 Foundation

Lists — ordered, mutable collections

Foundation lesson for lists and tuples. Start with the theory and syntax, then connect to a real playlist example.

Picture this: a numbered row of boxes

A list keeps items in order. Index 0 is the first box.

[0]first
→
[1]second
→
[2]third
→
len(list)how many boxes

You can change a list later (append, replace, slice).

In easy words: What is a list?

A list is a single box that stores many values in order. Think of it like a queue or playlist: first item, second item, third item. Python gives each position a number (index), so you can quickly pick or change any item.

Diagram — List indexes

10 index 0 20 index 1 30 index 2 40 index 3 nums = [10, 20, 30, 40] → nums[2] is 30

Where lists are used

Lists are used in shopping carts, marks of students, playlists, chat messages, and any situation where you have many items of the same kind and want to process them one by one.

What is a list?

  • Ordered — items stay in the order you put them.
  • Indexed from 0 — first item is list[0], last is list[-1].
  • Mutable — you can add, remove, or change items.
  • Mixed types allowed — [1, "hi", True] is valid.

Tuple vs List

  • Tuple uses ( ) and is immutable — values cannot change.
  • Use tuples for fixed data: coordinates (lat, lon), RGB (255,0,0).
  • Use lists when you need to add/remove/update items.

Real world: music playlist

A playlist is a list of songs in order. You access track 1 at index 0, skip to the last at index -1, and slice the "top 3" with playlist[0:3]. Apps also append new songs, remove them, and sort by rating — all list operations.

Click an item — inspect index, value, and slice

Playlist list visualizer

Click a cell to inspect

Slice: playlist[ : ]

Common list operations
Click an operation above

Syntax reference

1nums = [10, 20, 30, 40]
2print(nums[0]) # 10 — first item
3print(nums[-1]) # 40 — last item
4print(nums[1:3]) # [20, 30] — slice
5nums.append(50) # [10, 20, 30, 40, 50]

Example Program

1nums = [10, 20, 30]
2nums.append(40)
3print(nums)

Lists — Topic Quiz

Check understanding

Answer all questions, then click Check answers. Use this before Practice in the editor.

Q1. What is a list?

Q2. In `nums = [10, 20, 30]`, what is `nums[0]`?

Q3. How do you reverse a list in place?

Q4. Counting evens usually checks…

Score: —