Chrome Extension

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
We are a bunch of lazy programmers so we developed this chrome extension
search code from your favorite search engine
Install Now
Output
apple
("banana", "orange")
("orange", "apple")
grapes

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?
0 Comments
Open Code Manager We are hiring