tuple in python by R4R Team

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 0’th 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.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!