Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on 19 Dec

Total questions: 10

Worksheet time: 3mins

Name
Class
Date
1.

1. 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

2.

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

3.

Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in the dictionary which command do we use?

a)

d.size()

b)

len(d)

c)

size(d)

d)

d.len()

4.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

a.clear()

print(a)

a)

None

b)

{ None:None, None:None, None:None}

c)

{1:None, 2:None, 3:None}

d)

{ }

5.

Output?

a={1:5,2:3,3:4}

print(a.pop(4,9))

a)

9

b)

3

c)

Too many arguments

d)

4

6.

Output?

a={1:"A",2:"B",3:"C"}

for i in a:

print(i,end=" ")

a)

1 2 3

b)

‘A’ ‘B’ ‘C’

c)

1 ‘A’ 2 ‘B’ 3 ‘C’

d)

Error, it should be: for i in a.items():

7.

output?

d1={"abc":5,"def":6,"ghi":7}

print(d1[0])

a)

abc

b)

5

c)

{"abc":5}

d)

Error

8.

Which of the following will delete key_value pair for key="tiger" in the dictionary?

dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}

a)

del dic["tiger"]

b)

dic["tiger"].delete()

c)

delete(dic.["tiger"])

d)

del(dic.["tiger"])

9.

Which of these about a dictionary is false?

a)

The values of a dictionary can be accessed using keys

b)

The keys of a dictionary can be accessed using values

c)

Dictionaries aren’t ordered

d)

Dictionaries are mutable

10.

Which of the following isn’t true about dictionary keys?

a)

More than one key isn’t allowed

b)

Keys must be immutable

c)

Keys must be integers

d)

When duplicate keys encountered, the last assignment wins