Professional Documents
Culture Documents
2.4.py Gaurav
2.4.py Gaurav
WORKSHEET 2.4
Student Name: Gaurav Kumar UID: 21BCS5875
Branch: CSE Section/Group: 812-A
Semester:4th Date of Performance:24/4/23
Subject Name: Programming in Python Subject Code: 21CSP-259
Aim: Program to demonstrate creation and accessing of tuples and applydifferent kinds of
operations on them.
Source Code:
1. Write a Python program to replace last value of tuples in a list.
my_list = [(1, 2), (3, 4), (5, 6)]
new_value = 10
new_list = [(x[0], new_value) for x in my_list]
print(new_list)
Output:
Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
3. Write a Python program calculate the product, multiplying all thenumbers of a given
tuple.
my_tuple = (1, 2, 3, 4, 5)
product = 1
for num in my_tuple:
product *= num
print(product)
OUTPUT:
Output: