List

An ordered, changeable collection of items written in square brackets.

A list is an ordered, changeable collection written in square brackets, like [1, 2, 3]. Items keep their order, can be of mixed types, and are reached by position starting at 0items[0] is the first and items[-1] the last. Lists are mutable: you can append, insert, replace, and remove items after creating them.

Example
fruits = ["apple", "pear", "plum"]
fruits.append("kiwi")   # lists can grow
print(fruits[0])        # first item
print(fruits[-1])       # last item
print(len(fruits))      # how many items
Output
apple
kiwi
4

Where this shows up in real Python

Lists collect things in order: rows read from a file, a queue of tasks, or results you build up as a loop runs.

Commonly used List tools

list is a built-in type — the methods you’ll reach for most:

  • .append(x) — add one item to the end
  • .extend(items) — add several items
  • .insert(i, x) — add at a position
  • .remove(x) — delete the first matching item
  • .pop(i) — remove and return an item
  • .sort() / sorted(seq) — order in place / return a sorted copy
  • len(seq), seq[1:3], x in seq — length, slice, membership

Official documentation: Python Tutorial: More on Lists

Related lessons

Related terms