Monday, September 14, 2026

Python Lists: Mutability Quiz

 Python Lists: Mutability Quiz


1. What is the output of this Python code? x = [1, 2, 3] x[0] = 10 print(x)

   A. [10, 2, 3]

   B. [1, 2, 3]

   C. [10, 1, 2, 3]

   D. TypeError


2. What is the output of this Python code? items = [1, 2] items.append(3) print(items)

   A. [1, 2]

   B. [1, 2, 3]

   C. [3, 1, 2]

   D. [1, 2, [3]]


3. What is the output of this Python code? a = [10, 20] b = a b[1] = 99 print(a)

   A. TypeError

   B. [99, 20]

   C. [10, 99]

   D. [10, 20]


4. Which statement correctly describes Python lists?

   A. Lists cannot contain duplicate values.

   B. Lists are mutable sequences.

   C. Lists can contain only numbers.

   D. Lists are immutable sequences.


5. What is the output of this Python code? numbers = [1, 2, 3] numbers[1] = 20 print(numbers)

   A. [1, 20, 3]

   B. [1, 2, 20, 3]

   C. [1, 2, 3]

   D. [20, 2, 3]

1 comment:

perlknowledge said...

What is the output of this Python code?
items = [1, 2] items.append(3) print(items)
append() mutates the list and places the new element at the end.


What is the output of this Python code?
a = [10, 20] b = a b[1] = 99 print(a)
b refers to the same mutable list as a, so the second element becomes 99.

Which statement correctly describes Python lists?
Lists allow elements to be changed, added, or removed after creation.

What is the output of this Python code?
numbers = [1, 2, 3] numbers[1] = 20 print(numbers)
The second element is replaced with 20, demonstrating list mutability.