Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Lists & Tuples — W3Schools Style Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the correct way to create a list in Python?

a)

mylist = {1, 2, 3}

b)

mylist = [1, 2, 3]

c)

mylist = (1, 2, 3)

d)

mylist = <1, 2, 3>

2.

Which of the following creates an empty tuple?

a)

t = []

b)

t = {}

c)

t = ()

d)

t = tuple[]

3.

What will be the output of the following code? a = [1, 2, 3] print(a[1])

a)

A) 1

b)

B) 2

c)

C) 3

d)

D) IndexError

4.

What will be the output? fruits = ['apple', 'banana', 'cherry'] fruits[1] = 'mango' print(fruits)

a)

['apple', 'banana', 'cherry']

b)

['mango', 'banana', 'cherry']

c)

['apple', 'mango', 'cherry']

d)

Error: Tuples are immutable

5.

What is the output of the following code? numbers = (10, 20, 30) numbers[0] = 99 print(numbers)

a)

A) (99, 20, 30)

b)

·         B) ['mango', 'banana', 'cherry']

c)

·         C) ['apple', 'mango', 'cherry']

d)

D) Error: Tuples are immutable

6.

Which of the following is True about lists and tuples?

a)

Lists are immutable, tuples are mutable.

b)

Tuples are immutable, lists are mutable.

c)

Both lists and tuples are mutable.

d)

Both lists and tuples are immutable.

7.

What is the output? nums = [1, 2, 3] nums.append([4, 5]) print(len(nums))

a)

A) 3

b)

B) 4

c)

C) 5

d)

D) 6

8.

What is the result of this code?

x = [1, 2, 3]
y = x
y.clear()
print(x)

a)

A) [1, 2, 3]

b)

B) []

c)

C) None

d)

D) Error

9.

What is the difference between del x and x.clear() when x is a list?

a)

No difference at all.

b)

x.clear() deletes the variable, del x empties it.

c)

x.clear() empties the list but keeps the variable, del x deletes the variable itself.

d)

Both throw an error.

10.

What is the output? a = [1, 2, 3] b = a.copy() b.append(4) print(a)

a)

A) [1, 2, 3, 4]

b)

B) [1, 2, 3]

c)

C) [4]

d)

D) Error

11.

What will happen here? x = (5) print(type(x))

a)

A) <class 'tuple'>

    

b)

B) <class 'list'>

c)

C) <class 'int'>

d)

D) SyntaxError

12.

Find the output: a = [1, 2, 3] b = (1, 2, 3) print(a * 2) print(b * 2)

a)

A) [1, 2, 3, 1, 2, 3] and (1, 2, 3, 1, 2, 3)

b)

B) [1, 2, 3] and (1, 2, 3)

c)

C) Error

d)

D) [1, 2, 3] and [1, 2, 3]

13.

Predict the output: nums = [1, 2, 3, 4] print(nums.pop(2)) print(nums)

a)

A) 3 and [1, 2, 4]

b)

B) 2 and [1, 3, 4]

c)

C) Error

d)

D) [1, 2, 3, 4]

14.

Which of the following statements will raise an error?

a)

tuple1 = (1, 2) + (3, 4)

b)

tuple2 = (1, 2) * 2

c)

tuple3 = (1, 2).append(3)

d)

tuple4 = tuple((1, 2, 3))

15.

Debug the following code: my_list = [1, 2, 3] print(my_list[3]) What happens and why?

a)

A) Prints 3

b)

B) Prints None

c)

C) Raises IndexError because index 3 is out of range

d)

D) Prints nothing