EN
Python - access list items
0
points
In this article, we would like to show you how to access list items in Python.
Quick solution:
my_list = ['A', 'B', 'C']
print(my_list[0]) # A
print(my_list[-3]) # A
1. Positive indexing
In this example, we use positive indexing to access list items by refering to the specific index number. We start from index 0
that refers to the first item.
my_list = ['A', 'B', 'C']
print(my_list[0]) # A
print(my_list[1]) # B
print(my_list[2]) # C
Output:
A
B
C
2. Negative indexing
In this example, we use negative indexing to access list items by refering to the specific index number. We start from index -1
that refers to the list item.
my_list = ['A', 'B', 'C']
print(my_list[-1]) # C
print(my_list[-2]) # B
print(my_list[-3]) # A
Output:
C
B
A