wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Unit 9

Total questions: 10

Worksheet time: 7mins

Name
Class
Date
1.

Given the following list,

my_list = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11] ]

Which line of code would print the number ‘5’ to the screen?

a)

print(my_list[1])

b)

print(my_list[1:2])

c)

print(my_list[1][2])

d)

print(my_list[2][3])

2.

What kind of data structure is user_data in the following declaration?

user_data = {"name": "TJ", "age":24, "user_name":"artLover123"}

a)

Tuple

b)

List

c)

Dictionary

d)

2D List

3.

What is the output of this program?

a)

12

45

1

3

7

2

5

8

3

b)

12

3

5

45

7

8

1

2

3

c)

12

3

5

d)

3

2

1

8

7

45

5

3

12

4.

Which of the following code snippets will create this 2D list?

a)

board = [1, 2, 3] + [4, 5, 6] + [7, 8, 9]

b)

board = [1, 2, 3]

board.append([4, 5, 6])

board.append([7, 8, 9])

c)

board = [1, 2, 3, 4, 5, 6, 7, 8, 9]

d)

board = [] board.append([1, 2, 3]) board.append([4, 5, 6]) board.append([7, 8, 9])

5.

Which of the following list comprehensions will create the same list as the for loop below?

a)

my_list = [i for i in range(6)]

b)

my_list = [i*2 for i in range(6)]

c)

my_list = [i for i*2 in range(6)]

d)

This cannot be done using a list comprehension statement.

6.

What does “packing” refer to in Python?

a)

Creating a list

b)

Initializing variables using values from a list

c)

Storing multiple variables’ values by putting them in a collection, like a list or tuple

d)

Cramming as many commands as possible onto a single line

7.

What does “unpacking” refer to in Python?

a)

Creating a list

b)

Initializing multiple variables at a time using a collection of values

c)

Storing multiple variables’ values by putting them in a collection, like a list or tuple

d)

Cramming as many commands as possible onto a single line

8.

Which of the following assignment statements is equivalent to the following code snippet?

red, blue, green = "BLUE", "GREEN", "RED"

a)

red = "RED"

blue = "BLUE" green = "GREEN"

b)

red = "BLUE"

blue = "GREEN" green = "RED"

c)

red = ["BLUE", "GREEN", "RED"]

blue = ["BLUE", "GREEN", "RED"] green = ["BLUE", "GREEN", "RED"]

d)

red = "BLUE"

blue = "BLUE" green = "BLUE"

9.

A dictionary maps:

a)

strings to strings

b)

strings to numbers

c)

indices to elements

d)

keys to values

10.

Use the following definitions of foods and groceries.

foods = ["apples", "eel", "kale"]

groceries = ["apples", "eel", "kale"]

Which of the following statements would evaluate to True about foods and groceries?

I. foods == groceries

II. foods is groceries

a)

I only

b)

II only

c)

Both I and II

d)

Neither I nor II