Tuples are an ordered, immutable sequence of Python objects. They are similar to lists, but cannot be changed after creation.
Tuples are created using parentheses ()
.
my_tuple = (1, "hello", 3.14)
Elements are accessed using indexing, similar to lists.
print(my_tuple[0]) # Output: 1
Common tuple operations include:
+
.in
.Tuples are useful when you need to ensure that data remains constant. Common use cases include representing fixed records or returning multiple values from a function.