Tuple¶
Tuple is an immutable list. Any attempt to change/update tuple will return erro.
Benefits of tuple against List are:
- Faster than list
- Protects your data against accidental change
- Can be used as key in dictionaries, list can't
In [28]:
t = (1,2,3,'o','apple') print (t) type (t)
(1, 2, 3, 'o', 'apple')
Out[28]:
tuple
In [29]:
len(t)
Out[29]:
5
Accessing¶
In [30]:
print (t[1]) print (type(t[1]))
2 <class 'int'>
In [31]:
print (t[1:3]) type ([t[1:3]])
(2, 3)
Out[31]:
list