Tuple is used to store multiple values. tuple created using small brackets ()
t= (1, 2, 3)
Tuple are immutable.
Print tuple
t=(1,2,3)
print(t)
Tuple Indexing
t=(1,2,3)
print(t[0]) # 1
Tuple splitting
t=(1,2,3)
print( t[0:2] ) # (1, 2)
Tuple looping
t=(1, 2, 3)
for item in t:
print(item)
Tuple methods
index(item) | Return index of given item from a tuple |
t=(1,2,3) |
count(item) | Return number of item of specified item from a tuple |
t=(1,2,3,1) |