A Tuple is a collection of Python objects separated by commas.
In someways a tuple is similar to a list in terms of indexing, nested objects and repetition but a tuple is immutable unlike lists which are mutable.
Example - 1:
# Creating non-empty tuples # One way of creation tup ='python','gyansetu'print(tup)# Another for doing the same tup = ('python','gyansetu') print(tup)
('python', 'gyansetu')
('python', 'gyansetu')
Example - 2:
t = ( 5,6,7)print(t)print(type(t))
(5, 6, 7)
<class 'tuple'>
Example - 3:
#code to test that tuples are immutable tuple1 = (0,1,2,3) tuple1[0]=4print(tuple1)