Lesson 6
Dealing with Sequences of Objects
Chapter 2: Lists
Accessing elements in a list
Each item in a list is called an element.
You can access each element by referring to its index.
The index starts from 0 (i.e. the first item’s index is 0).
>>> students = ["Abraham", "Bella", "Connor", "Da-ming", "Enya"]
>>> print(students[0]) # First element: "Abraham"
Abraham
>>> print(students[1]) # Second element: "Bella"
Bella
Python also allows you to access elements in a list in a reverse order, with negative indices.
>>> print(students[-1]) # First element from the end
Enya
>>> print(students[-2]) # Second element from the end
Da-ming