ExamVeda
Login
Home
This question belongs to Python Program Tuples In Python
Tuples in Python
?

What will be the output of the following code:
my_tuple = (1, 2, 3)
my_tuple[1] = 4
print(my_tuple)

Answer & Solution
Correct Answer: Option D
Tuples in Python are immutable, meaning their elements cannot be changed after creation.

In the given code, my_tuple = (1, 2, 3) initializes a tuple with three elements.

The line my_tuple[1] = 4 attempts to modify the second element of the tuple, which is not allowed.

As a result, Python raises a TypeError stating that 'tuple' object does not support item assignment.

Since the code causes an error and does not produce any valid tuple as output, the correct answer is "None of these."
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Karthika N
Karthika N 2 years ago
Tuples in Python are immutable, meaning their elements cannot be changed after assignment.. So your answer is wrong.