In Python, tuples are immutable sequences used to store collections of items. You can access individual elements in a tuple using their index. Indexing in Python starts at 0, meaning the first item in a tuple has an index of 0, the second item has an index of 1, and so on.
To access elements in a tuple, you can simply use the tuple name followed by the index enclosed in square brackets. Here is an example of how to index a tuple:
# Defining a tuple
my_tuple = (10, 20, 30, 40, 50)
# Accessing elements using indexing
first_element = my_tuple[0] # 10
second_element = my_tuple[1] # 20
last_element = my_tuple[-1] # 50 (negative index for last element)
print(first_element) # Output: 10
print(second_element) # Output: 20
print(last_element) # Output: 50
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?