A tuple is a data structure that is an immutable, or unchangeable, ordered sequence of elements. Because tuples are immutable, their values cannot be modified.
Generally, tuples use less memory than a list or array. It allows for slicing and indexing like lists but do not have methods for deleting or changing elements.
Key Characteristics of Tuples:
- Immutable: You cannot modify, add, or remove items after creating the tuple.
- Ordered: Items in a tuple maintain their defined order.
- Can Store Different Data Types: Each element in a tuple can be of any data type.
- Supports Indexing: Access elements using indices starting from 0.
Example (Python):
# creating a tuple
mySiblings = ('Susan', 'James', 'Bryan')
# accessing an element within a tuple:
mySiblings[2]