Q:

Given is a nested tuple. Write a program to modify the first item (22) of a list inside a following tuple to 222

belongs to collection: Python Tuple Exercises

0

Modify the tuple

Given is a nested tuple. Write a program to modify the first item (22) of a list inside a following tuple to 222

Given:

tuple1 = (11, [22, 33], 44, 55)

Expected output:

tuple1: (11, [222, 33], 44, 55)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

The given tuple is a nested tuple. Use indexing to locate the specified item and modify it using the assignment operator.

Solution:

tuple1 = (11, [22, 33], 44, 55)
tuple1[1][0] = 222
print(tuple1)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Sort a tuple of tuples by 2nd item using python pr... >>
<< Write a python program to copy elements 44 and 55 ...