index

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

List can be iterated through:

for i in t:

print\(i\)

Convert to List, use function tuple()

For example:

n=12345

tuple(n) becomes (1,2,3,4,5)

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