Python Tuples

This topic is to discuss the following lesson:

Hi Rene,

What does it mean that You could use a tuple to “write protect” the contents of the tuple since you can’t modify it.

Hello Pradyumna

One of the characteristics of a tuple data type as opposed to a list is that it is immutable. This means that the value stored within the variable cannot be changed. For example, if you try to change a value within the tuple, it will return an error, as shown in the lesson.

Since the values stored within a tuple cannot be changed, we can say that they are “write protected” in much the same way as a write protected file cannot be changed. In other words, if you use a tuple in your programming, you can be sure that even an error in coding cannot change the contents, so if this is important to the purpose of your code, then using a tuple can be useful.

The term was used here simply to emphasize that the contents of a tuple cannot be changed.

I hope this has been helpful!