Skip to content

3.1.1 List Definition and Access

A list is defined using square brackets and elements are separated by commas.
Each element in a list has a position called an index.


Defining a List

Lists can contain:

  • Numbers
  • Strings
  • Other lists
  • Mixed data types

Lists preserve the order in which elements are added.


Accessing List Elements

  • List elements are accessed using their index
  • Indexing starts at zero
  • Negative indices access elements from the end

Accessing elements correctly is essential for data processing and iteration.


📌 Note:
Accessing an index outside the list range causes an error.