5.3. Tuples#

  • Tuples just like lists except that they are immutable. Once you have created a tuple, you cannot modify it.

  • Why use them?

    • Faster than lists

    • Make code safer – because you cannot change it

    • Valid keys in a dictionary

5.3.1. Actually you can modify a tuple#

my_tuple = (1, 2, 3, [4, 5, 6])
my_tuple[3].append(7)
print(my_tuple)
(1, 2, 3, [4, 5, 6, 7])