KnowledgeBoat Logo

Computer Science

Which of the following statement(s) would give an error during execution of the following code ?

tup = (20, 30, 40, 50, 80, 79)
print(tup) #Statement 1
print(tup[3] + 50) #Statement 2
print(max(tup)) #Statement 3
tup[4] = 80 #Statement 4
  1. Statement 1
  2. Statement 2
  3. Statement 3
  4. Statement 4

Python Tuples

2 Likes

Answer

Statement 4

Reason — The statement that would give an error during execution of the given code is Statement 4 (tup[4] = 80). This is because tuples in Python are immutable, meaning we cannot modify the elements of a tuple after it has been created. Here, it is attempting to assign 80 to the element at the index 4 of a tuple, which results in an error because tuples do not support item assignment.

Answered By

3 Likes


Related Questions