In Python, list elements are accessed using indexing. The index of the first element is 0, the second element is 1, and so on. You can also use negative indexing to access elements from the end of the list, where -1 refers to the last element, -2 to the second last, and so forth.
Here’s an example:
my_list = [10, 20, 30, 40, 50]
# Accessing elements using positive indexing
first_element = my_list[0] # 10
second_element = my_list[1] # 20
# Accessing elements using negative indexing
last_element = my_list[-1] # 50
second_last_element = my_list[-2] # 40
print(first_element, second_element, last_element, second_last_element)
This will output:
10 20 50 40
