Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET- 2.4
Student Name: Harsh Raj UID: 21BCS8426
Branch: CSE Section/Group: 719/A
Semester: 4th Date of Performance: 12/04/23
Subject Name: Programming in Python Lab Subject Code: 21CSP-259

1. Aim: Program to demonstrate creation, accessing of tuples and applying different


kinds of operations on them.
1. Create a tuple with 3 simple elements and 2 nested elements (one is a list, the second is a
tuple) and perform the following:
a. Write the Python script to explain the concept of membership operators in a
tuple.
b. Write the Python script to update the value inside the nested element.
c. Write the Python script to delete any random element.
2. Write the Python program to explain the concept of iteration over tuples.
3. Write the Python script to create a tuple with one single element of user choice
(runtime), then show the difference between the clear method and del method in tuples.
2. Source Code:
1. a.
t1=("Harsh",12,8.9,[1,4,7],(2,5,8))
print("Harsh" in t1)
print(12 not in t1)
print(8.9 in t1)
print((1,4,7)in t1)
print(7 in t1)
print(9 not in t1)

b.
t1=("Harsh",12,8.9,[1,4,7],(2,5,8))
print("Before",t1)
t1[3][1]=3
print("After",t1)
c.
t1=("Harsh",12,8.9,[1,4,7],(2,5,8))
del t1 [2]
print(t1)

2.
t1=("Harsh",12,8.9,(1,4,7),(2,5,8))
for i in t1:
print(i)

3.
a= input("Enter an element:")
t1=a,
'''
t1.clear()
print(t1)
'''
'''
del t1[0]
print(t1)
'''
del t1
print(t1)
4. Screenshot of Outputs:

1. a.

b.
c.

2.

3.

You might also like