Index Ai Academy
Phase 0 · ToolsPython core

Lists

About 20 minLooking ahead: some prerequisites aren't done yet

Why this matters

Data comes in collections. Rows from an export. A batch of headlines to score. The documents you'll search in a RAG system. The examples a model trains on. And when you call an LLM, the conversation you send is literally a list of messages. Lists are Python's usual way to hold many things in order.

  • Create a list and read items and slices from it by position
  • Add, change and remove items
  • Summarize a list with len, sum, min, max and sorted
  • Explain why two names can point at the same list, and make a real copy

Many values, in order

Think of a shopping list: several items, written in order, one after another. A Python list is the same. It holds several values in a fixed order. Write it with square brackets and commas:

channels = ["search", "display", "video", "email", "social"]
daily_clicks = [412, 388, 501, 467, 590]
empty = []

print(channels)
print(len(channels))      # how many items
print(len(empty))

A list can hold any type of value, even a mix. In practice, most lists hold one kind of thing: all names, or all numbers. Lists are often built from other data, as you saw with .split() in the strings lesson.

Indexing and slicing

Lists use the same positions as strings:

  • the first item is at index 0,
  • the last is at -1,
  • a slice [start:stop] stops before stop.

The difference is that each position holds a whole value, not a single character.