Python collection - Tuples in python

#Tuples are unchangable means you can not modify its items
fruits = ("banana", "orange", "apple", "grapes")

print(fruits[2]) #print third element apple

print(fruits[:3]) #print items start index to 0 and less than index 3

print(fruits[1:3]) #print tuple start from index 1 and less than index 3

print(fruits[-1]) #print last element
("banana", "orange")
("orange", "apple")

Tuples are python collections that can have multiple items and you can access them using its indexes. Tuples are unchangeable and you can not modify its items. In the code snippet, we have created a tuple named as 'fruits' which contains fruit names and we are printing fruit names by using different indexes. 

Was this helpful?