Lists & Tuples · Question 6 · Easy

An element of a tuple is assigned a new value. What happens?

t = (1, 2, 3)
t[0] = 9
print(t)
  1. (9, 2, 3)
  2. IndexError
  3. TypeError
  4. AttributeError
Answer and explanation

Answer: C. TypeError

Explanation: Tuples are immutable, so item assignment is not supported and Python raises TypeError. The print line is never reached.

Previous: A list is appended to another list. What length does this print? · Next: Two variables are exchanged using tuple packing and unpacking. What is printed?

Practise lists & tuples

Try a fresh set of lists & tuples questions with an explanation after every answer, free and without signing up: Lists & Tuples practice. Or sit a full placement mock test.

More lists & tuples questions

More python practice

Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge