December 2017
Beginner to intermediate
410 pages
12h 45m
English
A tuple is similar to a list, in that both can hold heterogeneous bits of information. The main difference is that the contents of a tuple are “immutable,” meaning they cannot be changed. They are also created with a pair of round brackets, ( ).
my_tuple =('a', 1, True, 3.14)
Subsetting items is accomplished in exactly the same ways as for a list (i.e., you use square brackets).
# get the first item print(my_tuple[0])
However, if we try to change the contents of an index, we will get an error.
# this will cause an error my_tuple[0] = 'zzzzz'