We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Basic Data Types
- Tuples
- Tutorial
Tuples
Tuples
Tuples are data structures that look a lot like lists. Unlike lists, tuples are immutable (meaning that they cannot be modified once created). This restricts their use because we cannot add, remove, or assign values; however, it gives us an advantage in space and time complexities.
A common tuple use is the swapping of numbers:
a, b = b, a
Here is a tuple, and it assigns itself the values of .
Another awesome use of tuples is as keys in a dictionary. In other words, tuples are hashable.