Tuple
# Creating non-empty tuples
# One way of creation
tup = 'python', 'gyansetu'
print(tup)
# Another for doing the same
tup = ('python', 'gyansetu')
print(tup) t = ( 5,6,7)
print(t)
print(type(t))Last updated
# Creating non-empty tuples
# One way of creation
tup = 'python', 'gyansetu'
print(tup)
# Another for doing the same
tup = ('python', 'gyansetu')
print(tup) t = ( 5,6,7)
print(t)
print(type(t))Last updated
#code to test that tuples are immutable
tuple1 = (0, 1, 2, 3)
tuple1[0] = 4
print(tuple1) l1 = [ 1,2,3]
l2 = [4,5,6]
t1 = ('hi','hello')
t2 = ('bye',1,2,3)
t3 = t1 + t2 #add both the tuples
print(t1)
print(t2)
print(t3)
l3 = l1+l2
print(l1)
print(l2)
print(l3)# code to test slicing
tuple1 = (0 ,1, 2, 3)
print(tuple1[1:])
print(tuple1[::-1])
print(tuple1[2:4])# Code for printing the length of a tuple
tuple2 = ('python', 'awesome')
print(len(tuple2)) # Code for converting a list and a string into a tuple
list1 = [0, 1, 2]
print(tuple(list1))
print(tuple(('python'))) # string 'python'