wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz 2.0

Total questions: 14

Worksheet time: 8mins

Name
Class
Date
1.

A dictionary is an example of a sequence ...

a)

True

b)

False

2.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

3.

Which of the following create an empty dictionary (D)?

a)

D = dict()

b)

D = ()

c)

D = []

d)

D = {}

4.
What data type is this?
quiz = {"Do you help out at home? ":"yes",        
"Do you beleive in Santa? ":"yes"
}
a)
list
b)
string
c)
dictionart
d)
dictionary
5.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
6.
is this code correct?
quiz = ("Do you help out at home? ":"yes"      }
a)
No
b)
Yes
c)
Both
7.

You have the following dictionary definition:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What method call will delete the entry whose value is 200?

a)

delete d('bar')

b)

d.pop("bar")

c)

d.remove("bar")

d)

None of the above

8.

Which method will remove an element the Dictionary data type?

a)

.pop()

b)

.discard()

c)

.remove()

9.

Please select all correct ways to empty the following dictionary

student = {

"name": "Emma",

"class": 9,

"marks": 75

}

a)

del student

b)

del student[0:2]

c)

student.clear()

10.

Items are accessed by their position in a dictionary

a)

True

b)

False

11.

_________________ method will not only delete the item from dictionary, but also return the deleted value.

a)

del ( )

b)

pop( )

c)

Clear( )

12.

________________method will returns number of key-value pairs in the given dictionary.

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

13.

Which of the following will give error?

Suppose dict1={"a":1,"b":2,"c":3}

a)

print(len(dict1))

b)

print(dict1.get("b"))

c)

dict1["a"]=5

d)

None of these.

14.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])