Python · Stage 5 – Grouping Data · Lesson 28 of 50

Lists: Grouping Values

Store an ordered group of values and read items by position.

colors = ["red", "blue", "green"]
Line-by-line explanation
  1. Square brackets begin and end the list.
  2. Commas separate its three string items.
  3. colors stores the entire list.
first = colors[0]
Line-by-line explanation
  1. colors is the list.
  2. [0] asks for its first item.
  3. first stores red.
some = colors[0:2]
Line-by-line explanation
  1. The slice starts at index 0.
  2. It stops before index 2.
  3. some stores red and blue.