WorksheetsPython Lists & Tuples — W3Schools Style Quiz
Total questions: 15
Worksheet time: 8mins
What is the correct way to create a list in Python?
mylist = {1, 2, 3}
mylist = [1, 2, 3]
mylist = (1, 2, 3)
mylist = <1, 2, 3>
Which of the following creates an empty tuple?
t = []
t = {}
t = ()
t = tuple[]
What will be the output of the following code? a = [1, 2, 3] print(a[1])
A) 1
B) 2
C) 3
D) IndexError
What will be the output? fruits = ['apple', 'banana', 'cherry'] fruits[1] = 'mango' print(fruits)
['apple', 'banana', 'cherry']
['mango', 'banana', 'cherry']
['apple', 'mango', 'cherry']
Error: Tuples are immutable
What is the output of the following code? numbers = (10, 20, 30) numbers[0] = 99 print(numbers)
A) (99, 20, 30)
· B) ['mango', 'banana', 'cherry']
· C) ['apple', 'mango', 'cherry']
D) Error: Tuples are immutable
Which of the following is True about lists and tuples?
Lists are immutable, tuples are mutable.
Tuples are immutable, lists are mutable.
Both lists and tuples are mutable.
Both lists and tuples are immutable.
What is the output? nums = [1, 2, 3] nums.append([4, 5]) print(len(nums))
A) 3
B) 4
C) 5
D) 6
What is the result of this code?
x = [1, 2, 3]
y = x
y.clear()
print(x)
A) [1, 2, 3]
B) []
C) None
D) Error
What is the difference between del x and x.clear() when x is a list?
No difference at all.
x.clear() deletes the variable, del x empties it.
x.clear() empties the list but keeps the variable, del x deletes the variable itself.
Both throw an error.
What is the output? a = [1, 2, 3] b = a.copy() b.append(4) print(a)
A) [1, 2, 3, 4]
B) [1, 2, 3]
C) [4]
D) Error
What will happen here? x = (5) print(type(x))
A) <class 'tuple'>
B) <class 'list'>
C) <class 'int'>
D) SyntaxError
Find the output: a = [1, 2, 3] b = (1, 2, 3) print(a * 2) print(b * 2)
A) [1, 2, 3, 1, 2, 3] and (1, 2, 3, 1, 2, 3)
B) [1, 2, 3] and (1, 2, 3)
C) Error
D) [1, 2, 3] and [1, 2, 3]
Predict the output: nums = [1, 2, 3, 4] print(nums.pop(2)) print(nums)
A) 3 and [1, 2, 4]
B) 2 and [1, 3, 4]
C) Error
D) [1, 2, 3, 4]
Which of the following statements will raise an error?
tuple1 = (1, 2) + (3, 4)
tuple2 = (1, 2) * 2
tuple3 = (1, 2).append(3)
tuple4 = tuple((1, 2, 3))
Debug the following code: my_list = [1, 2, 3] print(my_list[3]) What happens and why?
A) Prints 3
B) Prints None
C) Raises IndexError because index 3 is out of range
D) Prints nothing
