In [5]:
#It looks like a list but it's immutable (can't be modified)
myTuple = (1,'Hello',3,6)
print 'Last element in myTuple is: {x} '.format(x = myTuple[-1])
In [8]:
myTuple = (1,'Hello',3,6,3)
#find index of a certain value
idx = myTuple.index(3)
print 'Index of 3 is: {x}'.format(x = idx)
#Count repetition of a value in tuple
numRepeat = myTuple.count(3)
print 'Number of repetation of 3 is: {x}'.format(x = numRepeat)
In [ ]:
# Tuple Immutability
l = [1,2,3,5]
t = (1,2,3,5)
print 'list is: {x}'.format(x = l)
l[0] = 'Hello'
print 'list after modification is: {x}'.format(x = l)
print 'tuple is: {x}'.format(x = t)
t[0] = 'Hello' #will not work
print 'tuple after modification is: {x}'.format(x = t)