Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Summary module-2

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

1. Which of the following commands will create a list?

a)

a) list1 = list()

b)

b) list1 = []

c)

c) list1 = list([1, 2, 3])

d)

d) all of the mentioned

2.

What is the output when we execute list(“hello”)?

a)

[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

b)

[‘hello’]

c)

[‘llo’]

d)

[‘olleh’]

3.

To shuffle the list(say list1) what function do we use?

a)

list1.shuffle()

b)

shuffle(list1)

c)

random.shuffle(list1)

d)

random.shuffleList(list1)

4.

Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?

a)

print(list1[0])

b)

print(list1[:2])

c)

print(list1[:-2])

d)

all of the mentioned

5.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

[2, 33, 222, 14]

b)

Error

c)

25

d)

[25, 14, 222, 33, 2]

6.

Which of the following statements create a dictionary?

a)

d = {}

b)

d = {“john”:40, “peter”:45}

c)

d = {40:”john”, 45:”peter”}

d)

All of the mentioned

7.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

"john" in d

a)

True

b)

False

c)

None

d)

Error

8.

Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

a)

d.delete(“john”:40)

b)

d.delete(“john”)

c)

del d[“john”]

d)

del d(“john”:40)

9.

Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?

a)

Since “susan” is not a value in the set, Python raises a KeyError exception

b)

It is executed fine and no exception is raised, and it returns None

c)

Since “susan” is not a key in the set, Python raises a KeyError exception

d)

Since “susan” is not a key in the set, Python raises a syntax error

10.

What will be the output of the following Python code?

t = (1, 2)

2 * t

a)

(1, 2, 1, 2)

b)

[1, 2, 1, 2]

c)

(1, 1, 2, 2)

d)

[1, 1, 2, 2]