Explanation:
Tuples are immutable: This means that once a tuple is created, its elements cannot be changed. Any attempt to modify an element in a tuple, as shown in the code, will result in an error.
Error: The code will raise a TypeError because Python does not allow the modification of elements in a tuple.
my_tuple = (3, 5, 7)
new_tuple = (my_tuple[0], my_tuple[1] + my_tuple[0], my_tuple[2])
3,5 + 3,7
print(new_tuple)
# The Given Instruction:
# my_tuple[1] = my_tuple[1] + my_tuple[0]
# This instruction tries to change the element at index 1 of my_tuple by adding the element at index 0 to it.
# Attempting to Modify a Tuple:
# Since tuples are immutable, any attempt to directly change an element in a tuple will result in a TypeError.
A is correct.
TypeError: 'tuple' object does not support item assignment
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Vihaan_C
2 weeks, 6 days agoconsultsk
1 month, 3 weeks agoPoojasr
2 months, 3 weeks agochristostz03
3 months agoSupatekooma
3 months, 2 weeks agoherrmann69
5 months, 3 weeks ago