Tuple
Tuple
immutable, tuple can not be modified. Modify a tuple variable result in a new tuple.
Tuple usually is in parentheses (), for example: (1,2,3,4,5) or (‘a’,’b’,’c’) or (1,2,3,’a’,’b’,’10’)
However, parentheses is not indicative to tuple, comma is. Tuple must have comma.
Like list, tuple is a sequence, iterable
t=(‘a’,’b’,’c’)
t[0]=“a”
t[1]=“b”
t[2]=“c”
It is zero based indexing, index starts from zero
Tuple can be iterated through:
Convert to Tuple, use function tuple()
For example:
Tuple is an object, meaning it has methods and attributes that can be invoked
To see all methods, type
help(<tuple variable>)
In Jupyter notebook, to see list of methods or attributes
Press shift key after enter <tuple variable>.
Last updated