Tuple Operations
Here is a quick run-through of the operations you can do on tuples:
A. Making tuples:
T = () (the empty tuple, which is the tuple with no elements)
T = (x, ) (the tuple with 1 element). Note the comma.
T = (2, 3, 9, 1, 2) This makes a tuple with 5 elements
T = T1 + T2, where T1 and T2 are tuples. This concatenates T1 and T2 into a new tuple T.
T = T1 * 3, where T1 is a tuple. This makes a new tuple T, which is the concatenation of T1 3 times, as in T1 + T1 + T1.
B. Indexing:
T[0]: the first element in tuple T
T[1]: the second element in tuple T
etc.
C. Changing the contents of the tuple, without changing the list itself:
You can’t do this. There is no append() or delete() function for tuples.
You can’t even say T[0] = 5.
D. Other stuff
len(T): the length, or number of entries, of T
for x in T: iterates a loop over all entries of T
x in T: returns True if T has an entry whose value is x