In Python, lists are indexed starting from 0. This means that the first element in a list can be accessed using an index of 0, the second element with an index of 1, and so on. You can also use negative indices to access elements from the end of the list, where -1 refers to the last element, -2 to the second last, and so forth.
# Creating a sample list
fruits = ["apple", "banana", "cherry", "date"]
# Accessing elements using positive indices
print(fruits[0]) # Output: apple
print(fruits[2]) # Output: cherry
# Accessing elements using negative indices
print(fruits[-1]) # Output: date
print(fruits[-2]) # Output: cherry
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?