tuple_5
tuple_5
6 :- Tuple
Roll_No :- 05
Date :- 13/05/2025
# Creating a Tuple
tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Created tuple is :",tuple1)
Element at index 0: 10
Element at index 3: 3.14
Last element (index -1): True
# Tuple slicing
tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Before slicing :", tuple1)
b = tuple1[2:4]
print("After slicing :", b)
tuple : (1, 2, 3, 4)
tuple to list : [1, 2, 3, 4]
After insert item in tuple : (1, 2, 'Shubham', 3, 4)
# concate tuple
a =(1,2,3)
b= ('ram','Shubham','soham') c
=a+b
print("After concate a and b tuple :",c)
# vice -versa
c =b+a
print("After concate b and a tuple :",c)
# tuple operations
b = ('ram','Shubham','soham','ram')
c = b.count('ram')
print ("Count of ram :",c)
c = b.index('ram')
print ("index of ram :",c)
c = b[1:].index('ram')
print ("index of Second string ram :",c)
Count of ram : 2
index of ram : 0
index of Second string ram : 2
Whole program
# Creating a Tuple
tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Created tuple is :",tuple1)
# Tuple slicing
tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Before slicing :", tuple1)
b = tuple1[2:4]
print("After slicing :", b)
# concate tuple
a =(1,2,3)
b= ('ram','Shubham','soham') c
=a+b
print("After concate a and b tuple :",c)
# vice -versa
c =b+a
print("After concate b and a tuple :",c)
# tuple operations
b = ('ram','Shubham','soham','ram')
c = b.count('ram')
print ("Count of ram :",c)
c = b.index('ram')
print ("index of ram :",c)
c = b[1:].index('ram')
print ("index of Second string ram :",c)