Introduction to Python
A tuple is another 'container' (or sequence) data type in Python. A tuple consists of a number of values/variables separated by a comma and enclosed by parentheses. At this point, you see no difference from the lists. However, there are many that are worth pointing out.
The key aspect is mutability - lists are mutable while tuples are not. Remember that two chapters ago, you updated a list by using special methods (such as
.append()). These options are not available for tuples - you can not update an existing tuple without reassigning it. Tuples are also faster and consume less memory compared to lists. Since tuples are immutable, they are widely used for storing sensitive information.
You can convert an iterable object into a tuple by using the
Let's continue working with the same example data as before.