CS1430 — Intro to Programming in Python

Intro to Lists Widget

An interactive walkthrough of list syntax, indexing, slicing, and modifying values.

Choose a list to explore
List syntax anatomy
Key concepts
Identifier
The variable name that holds the list. Choose something descriptive.
Square brackets [ ]
Always wrap the list contents. An empty [] creates an empty list.
Elements
Any values separated by commas. Order is preserved.
Index
Each element has a position number starting at 0. Use list[i] to access it.
More examples
Empty list
empty = []
Mixed types are allowed
mixed = [42, "hello", 3.14, True]