You are on page 1of 6

1 Python Experiment NO 07

FS20CO047
Experiment 9

Shrikrushna Dilip Patil


13th November, 2021
2 Python Experiment NO 07

Title: Write a Python program to perform


following operations on Tuples:
a) Create
b) Access
c) Update
d) Delete

Theory:
1.Explain tuples along with different operations:
a. Define Tuples in Two ways
To create a tuple, assign a single variable with multiple values
separated by commas in parentheses.

Code:
type1=(1,3,4,5,’test’)
print(type1)

b. Accessing Items in a Tuple


One can access the elements of a tuple in multiple ways, such as
indexing, negative indexing, range, etc.

Code:
Access_tuple=(‘a’,’b’,1,3,[5,’x’,’y’,’z’])
print(access_tuple[0])
print(access_tuple[4][1])
3 Python Experiment NO 07

output:-

c. Concatenation Operation On Tuple


Concatenation simply means linking things together. We can
concatenate tuples together. We can perform different operations
on tuples without changing its own definition.

Code:
Tuple1=(1,3,4,5)
Tuple2=(‘red’,’green’,’blue’)
Print(Tuple1 + Tuple2)

Output:
4 Python Experiment NO 07

d. Nesting Operation On Tuple


Nesting simply means the place or store one or more inside the
other.

Code:
Tuple1=(1,3,4,5)
Tuple2=(‘red’,’green’,’blue’)
Tuple3(Tuple1 + Tuple2)
Print(Tuple3)

Output:

d. Slicing Operation On Tuples


As tuples are immutable, we can take slices of one tuple and place
them in another tuple.

Code:
Tuple1=(1,3,4,’test’,’red’)
Sliced=(Tuple1[2:1])
Print(Sliced)
5 Python Experiment NO 07

Output:

f. Changing a Tuple
As we know that the tuples are immutable. This means that items
defined in a tuple cannot be changed once the tuple has been
created.

Code:
Tuple1=(1,2,3,[4,5])
Tuple1[3] [0] = 7
print(Tuple1)

Output:
6 Python Experiment NO 07

Practical:
a. Program to Create a tuple of 5 strings, and perform
various operations.
Program:-

Observation:
a.
Output:-

Conclusion:
In the above experiment In the above experiment I learned how to use the
Tuples and perform various operations on it.

You might also like