You are here: Home / Topics / What is tuple in python

What is tuple in python

Filed under: Python on 2022-08-23 13:37:20

Tuple in python also a sequence data type similar as list, item in tuple is separated by comma(,) and enclosed by parentheses.
Tuple is immutable that means in tuple we can not modified the index value.
Update is not allowed or addition new item are also not allowed
Tuple is read only list

Program-

t=(1,3,'Mytext','Myrule')
print(t)
print(t[0])
print(t[1:3])
print(len(t))

Output

(1, 3, 'Mytext', 'Myrule')
1
(3, 'Mytext')
4

In this program we create the tuple data type in python, and print it in different ways. Like in print(t[0]) will only display the item of 0th index or fisrt item and in print(t[1:3]) display the items 1 and 2 nd and len(t) display the length of the tuple.

About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.