wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python dictionary and set

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

2.

The code above prints

a)

Math

Physics

Chemistry

English

b)

4

3.8

3.6

3.7

c)

None

None

None

None

d)

NaN

NaN

NaN

NaN

3.

What is the output of the program above

a)

e

b)

y

c)

t

d)

g

4.

The output of the code above is

a)

[101, 102, 103, 104]

b)

[3.6, 3.7, 3.8, 4]

5.

What is the output of the code above

a)

[3.6, 3.7, 3.8, 4]

b)

[101, 102, 103, 104]

6.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
7.

Square brackets in an assignment statement will create which type of data structure?

( s=[] )

a)

List

b)

Queue

c)

Dictionary

d)

Set

8.

What will be the output of the following Python code?

nums = set([1,1,2,3,3,3,4,4])

print(len(nums))

a)

7

b)

Error, invalid syntax for formation of set

c)

4

d)

8

9.

Which of the following statements is used to create an empty set?

a)

{ }

b)

set()

c)

[ ]

d)

( )

10.

If a={5,6,7}, what happens when a.add(5) is executed?

a)

a={5,5,6,7}

b)

a={5,6,7}

c)

Error as there is no add function for set data type

d)

Error as 5 already exists in the set

11.

What will be the output of the following Python code?

>>> a={3,4,5}

>>> a.update([1,2,3])

>>> a

a)

Error, no method called update for set data type

b)

{1, 2, 3, 4, 5}

c)

Error, list can’t be added to set

d)

Error, duplicate item present in list

12.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> a.intersection_update({2,3,4,5})

>>> a

a)

{2,3}

b)

Error, duplicate item present in list

c)

Error, no method called intersection_update for set data type

d)

{1,4,5}

13.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=a

>>> b.remove(3)

>>> a

a)

{1,2,3}

b)

Error, copying of sets isn’t allowed

c)

{1,2}

d)

Error, invalid syntax for remove

14.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=a.copy()

>>> b.add(4)

>>> a

a)

{1,2,3}

b)

Error, invalid syntax for add

c)

{1,2,3,4}

d)

Error, copying of sets isn’t allowed

15.

What will be the output of the following Python code?

s=set()

type(s)

a)

<’set’>

b)

<class ‘set’>

c)

set

d)

class set