wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz on List and Tuples

Total questions: 16

Worksheet time: 10mins

Name
Class
Date
1.

What will be the output of the following code snippet?

a=[1,2,3,4,5,6,7,8,9]

print(a[::2])

a)

[1,2]

b)

[8,9]

c)

[1,3,5,7,9]

d)

[1,2,3]

2.

What will be the output of the following code snippet?

a=[1,2,3,4,5,6,7,8,9]

a[::2]=10,20,30,40,50,60

print(a)

a)

ValueError: attempt to assign sequence of size 6 to extended slice of size 5

b)

[10, 2, 20, 4, 30, 6, 40, 8, 50, 60]

c)

[1, 2, 10, 20, 30, 40, 50, 60]

d)

[1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]

3.

What will be the output of the following code snippet?

arr = [[1, 2, 3, 4],

[4, 5, 6, 7],

[8, 9, 10, 11],

[12, 13, 14, 15]]

for i in range(0, 4):

print(arr[i].pop())

a)

1 2 3 4

b)

1 4 8 12

c)

4 7 11 15

d)

12,13,14,15

4.

What will be the output of the following code snippet?

a=[1,2,3,4,5]

print(a[3:0:-1])

a)

Syntax error

b)

[4, 3, 2]

c)

[4, 3]

d)

[4, 3, 2, 1]

5.

Consider the following list

l1=[1,2,3]

L1 = [1,2,3]+[4,5,6]

what is L1

a)

[1,2,3,5,7,9]

b)

[1,2,3]

c)

[4,5,6]

d)

[1,2,3,4,5,6]

6.

In Python, list is mutable

a)

True

b)

False

7.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

8.

What sort of bracket is for lists?

a)

(

b)

<

c)

}

d)

[

9.

For tuples and list which is correct?

a)

List and tuples both are mutable.

b)

List is mutable whereas tuples are immutable.

c)

List and tuples both are immutable.

d)

List is immutable whereas tuples are mutable

HIDE ANSWER

10.

Which is a correctly declared tuple?

a)

a = ("orange", "yellow", "red")

b)

a = "orange", "yellow", "red"

c)

a = ["orange", "yellow", "red"]

d)

a = "orangeyellowred"

11.

Which line of code will give you an error? b = (4, 5, 6, 7, 8)

a)

b[2]

b)

b[0] = 1

c)

b[:3]

d)

b[-2]

12.

How would you refer to 3 in the following tuple? c = ((7,5),(5,8),(0,-1),(4,3))

a)

c[0][0]

b)

c(3)

c)

c[8]

d)

c[3][1]

13.

What is the index of the following tuple: y = ()

a)

0

b)

1

c)

There is none. It is an empty tuple

14.

Given a = "Hello world" what does list(a) do?

a)

creates a list separated by word (white spaces)

b)

creates a list separated by character

c)

nothing

d)

creates a blank list named a

15.

Can you have lists inside of tuples and vice versa?

a)

Yes

b)

No

16.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed