0% found this document useful (0 votes)
4 views2 pages

tuple_5

The document outlines Experiment No. 6 on Tuples, conducted by Shubham Shivaji Patil. It includes creating a tuple, accessing elements by index, slicing, inserting items, concatenating tuples, and performing operations like counting and indexing elements. The document provides code snippets and their outputs to illustrate each concept related to tuples in Python.

Uploaded by

shubhamsp9970
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

tuple_5

The document outlines Experiment No. 6 on Tuples, conducted by Shubham Shivaji Patil. It includes creating a tuple, accessing elements by index, slicing, inserting items, concatenating tuples, and performing operations like counting and indexing elements. The document provides code snippets and their outputs to illustrate each concept related to tuples in Python.

Uploaded by

shubhamsp9970
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment no.

6 :- Tuple

Name :- Shubham Shivaji Patil

Roll_No :- 05

Batch & class :- S1 & S.Y (A)

Date :- 13/05/2025
# Creating a Tuple
tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Created tuple is :",tuple1)

Created tuple is : (10, 20, 'Shubham', 3.14, True)

# Accessing Tuple Elements by Index


tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Element at index 0: ",tuple1[0])
print("Element at index 3: ",tuple1[3])
print("Last element (index -1): ",tuple1[-1])

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)

Before slicing : (10, 20, 'Shubham', 3.14, True) After


slicing : ('Shubham', 3.14)

# insert the item in tuple


a =(1,2,3,4)
print("tuple :",a)
b = list (a)
print("tuple to list : ", b)
b.insert(2,"Shubham") a=tuple(b)
print("After insert item in tuple :", a)

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)

After concate a and b tuple : (1, 2, 3, 'ram', 'Shubham', 'soham') After


concate b and a tuple : ('ram', 'Shubham', 'soham', 1, 2, 3)

# Accessing tuple item in reverse order


b= ('ram','Shubham','soham')
c= b [1][-2:-4:-1]
print("Specific index in reversse order :",c)

Specific index in reversse order : se

# 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)

# Accessing Tuple Elements by Index


tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Element at index 0: ",tuple1[0])
print("Element at index 3: ",tuple1[3])
print("Last element (index -1): ",tuple1[-1])

# Tuple slicing
tuple1 = (10, 20, 'Shubham', 3.14, True)
print("Before slicing :", tuple1)
b = tuple1[2:4]
print("After slicing :", b)

# insert the item in tuple


a =(1,2,3,4)
print("tuple :",a)
b = list (a)
print("tuple to list : ", b)
b.insert(2,"Shubham") a=tuple(b)
print("After insert item in tuple :", a)

# 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)

# Accessing tuple item in reverse order


b= ('ram','Shubham','soham')
c= b [1][-2:-4:-1]
print("Specific index in reversse order :",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)

Created tuple is : (10, 20, 'Shubham', 3.14, True)


Element at index 0: 10
Element at index 3: 3.14
Last element (index -1): True
Before slicing : (10, 20, 'Shubham', 3.14, True) After
slicing : ('Shubham', 3.14)
tuple : (1, 2, 3, 4)
tuple to list : [1, 2, 3, 4]
After insert item in tuple : (1, 2, 'Shubham', 3, 4)
After concate a and b tuple : (1, 2, 3, 'ram', 'Shubham', 'soham')
After concate b and a tuple : ('ram', 'Shubham', 'soham', 1, 2, 3)
Specific index in reversse order : se
Count of ram : 2
index of ram : 0
index of Second string ram : 2
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like