2.6.2 Tuples
Python Programming
In Python, tuples are a type of data structure used to store an ordered collection of items, similar to lists, but with a key difference: tuples are immutable, meaning their values cannot be changed after creation.
Example
python
# Creating a tuple
my_tuple = (1, 2, 3, "Hello", 4.5)
# Accessing elements by index
print(my_tuple[0]) # Output: 1
print(my_tuple[3]) # Output: Hello
# Tuple length
print(len(my_tuple)) # Output: 5