wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Unit 11 - Collections: Dictionary, List, Set, Tuple

Total questions: 40

Worksheet time: 20mins

Name
Class
Date
1.

To create a set, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

2.

To create a list, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

3.

To create a tuple, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

4.

To create a dictionary, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

5.

What type of data collection is this?

[ 3, 4, 5, 6 ]

a)

Dictionary

b)

List

c)

Set

d)

Tuple

6.

What type of data collection is this?

( 3, 4, 5, 6 )

a)

Dictionary

b)

List

c)

Set

d)

Tuple

7.

What type of data collection is this?

{ 3, 4, 5, 6 }

a)

Dictionary

b)

List

c)

Set

d)

Tuple

8.

What type of data collection is this?

{ student: "Bill", grade: 92, class: "Python" }

a)

Dictionary

b)

List

c)

Set

d)

Tuple

9.

What is a list in python?

a)

A collection of variables

b)

A collection of items assigned to a single variable

c)

A statement that cant be changed

d)

A Christmas list

10.

Which of these codes is correct for creating a list of numbers?

a)

num = ('10','29','37','109')

b)

num = ['10','29','37','109']

c)

num == ('10','29','37','109')

d)

num = ['10 29 37 109']

11.

What is the index number for 'Spain'?

['England','Brazil','Spain','France']

a)

0

b)

1

c)

2

d)

3

12.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

13.

Which code would i use to add an item to a list?

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

14.

variable.sort() will do what?

a)

Sort the list into alphabetical order

b)

Sort the list into reverse order

c)

Create a new list

d)

Error

15.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

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

d)

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

16.

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"]

17.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

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

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

18.

What would this code show on the screen?

a)

7

b)

6

c)

5

d)

4

e)

An error

19.

Each item in a list has an "address" or index. The first index in a Python list is what?

a)

1

b)

0

c)

a

d)

A

20.
What is the output when we execute list(“hello”)?
a)
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b)
 [‘hello’] 
c)
[‘llo’]
d)
 [‘olleh’]
21.

What is the output of program below?


mariana_islands = ['Saipan', 'Tinian', 'Rota']

del mariana_islands[0]

print(mariana_islands)

a)

['Saipan', 'Tinian', 'Rota']

b)

['Tinian', 'Rota']

c)

['Saipan', 'Tinian']

d)

['Saipan', 'Rota']

22.

What is the output of program below?


mariana_islands = ['Saipan', 'Tinian', 'Rota']

mariana_islands[0] = 'Guam'

print(mariana_islands)

a)

['Saipan', 'Tinian', 'Rota']

b)

['Guam', 'Tinian', 'Rota']

c)

['Saipan', 'Tinian', 'Rota', 'Guam']

d)

['Guam', 'Saipan', 'Tinian', 'Rota']

23.

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

The list will be slice and show Harry and Jesse only. Which piece of code below would do this?

a)

print(nameList[1:3])

b)

print(nameList[0:1])

c)

print(nameList[1:2])

d)

print(nameList["Harry":"Jesse"])

24.

Tuples in Python are mutable

a)

False

b)

True

25.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

26.

What will be the output?

var1=['sam', "Pam", 12,44]

var1[3]="Ram"

print(var1)

a)

['sam', 'Pam', 12, 44]

b)

['sam', 'Pam', 12, 'Ram']

c)

It will give an error

d)

['sam', 'Pam', 'Ram',44]

27.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

28.

Assume the key is the student's id and the value is the grade. Which of the following code will get the grade of student id 102.

a)

grades[102]

b)

grades.get(102)

c)

grades[2]

d)

grades[3]

e)

grades.key(102)

29.

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

a)

{ }

b)

set()

c)

[ ]

d)

( )

30.

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

31.

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}

32.

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

33.

What will be the output of the following Python code?

s=set()

type(s)

a)

<’set’>

b)

<class ‘set’>

c)

set

d)

class set

34.

Select all of the types of data collections that are ORDERED.

(that means items can be referenced by location or key)

a)

Dictionary

b)

List

c)

Tuple

d)

Set

35.

Select all of the types of data collections that ALLOW duplicate values.

a)

Dictionary

b)

List

c)

Tuple

d)

Set

36.

Select all of the types of data collections that ALLOW individual items within the collection to be changed or modified.

a)

Dictionary

b)

List

c)

Tuple

d)

Set

37.

Which command will allow you to attempt to remove an item from a set without raising an error if it isn't in the set.

a)

.remove( )

b)

.discard( )

c)

.pop( )

d)

.delete( )

38.

Which command will allow you to remove the last item in a collection.

a)

.remove( )

b)

.discard( )

c)

.pop( )

d)

.delete( )

39.

Which command will allow you to attempt to remove an item from a set and will raise an error if it isn't in the set

a)

.remove( )

b)

.discard( )

c)

.pop( )

d)

.delete( )

40.

Which method will combine the contents of two sets WITHOUT changing one of the existing sets?

a)

.update( )

b)

.union( )

c)

.add( )

d)

.intersection( )