wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Lists and Dictionaries

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

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

( s=[] )

a)

List

b)

Queue

c)

Dictionary

d)

Set

2.

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]

3.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

d)

"John"

4.

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

5.
What is the position of the name "Robert" in the following list:
a)
0
b)
1
c)
2
d)
3
6.

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

7.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
8.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

9.

To insert an the string "strawberries" in the first position of a list we use

a)

fruit.append("strawberries, 1")

b)

fruit.insert("strawberries",0)

c)

fruit.insert(1, "strawberries")

d)

fruit.insert(0, "strawberries")

10.

To print a list called fruitList we use

a)

print(fruitList)

b)

list(print)

c)

fruitList.print()

d)

fruitList(print)

11.

Which colour will be replaced with yellow?

a)

red

b)

green

c)

blue

d)

none, yellow will be added to the list

12.

Which symbols are used to open and close a list?

a)

( ) round brackets

b)

( ) curly brackets

c)

[ ] square brackets

d)

" " speech marks

13.

This list contains items of what data type?

a)

String

b)

Boolean

c)

Float

d)

Integer

14.

Choose all of the following which are built in data types in Python

a)

dict

b)

list

c)

set

d)

tuple

15.

A Python dictionary is called

a)

pytn

b)

dict

c)

dicn

d)

def

16.

Comparing a dictionary to Python to a dictionary for words, ____________ is each word we look up_______ is definition of the word

a)

value, key

b)

key, attribute

c)

method, value

d)

key, value

17.

Dictionaries use _________ and keys are separated with _________

a)

[], :

b)

{}, ()

c)

(), :

d)

{}, :

18.

In the following, what are the values? {‘name’: ‘Anna’, ‘age’: ‘22’, ‘courses’: [‘calculus’, ‘compsci’]}

a)

Anna, 22, calculus and compsci

b)

{}, :, '', []

c)

name, age, courses

19.

You can call up a value for just one key

a)

True

b)

False

20.

In the following, what are they keys? {‘name’: ‘Anna’, ‘age’: ‘22’, ‘courses’: [‘calculus’, ‘compsci’]}

a)

{}, :, '', []

b)

Anna, 22, calculus, compsci

c)

name, age, course

21.

______________ can be strings, integers and lists

a)

keys

b)

dictionaries

c)

methods

d)

values

22.

print(len(student)) would yield

a)

number of keys

b)

all keys

c)

all values

d)

keys and values

23.

if statements does not need indentation

a)

True

b)

False

24.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

25.

What is the output of the code above

a)

(1, '2', 3, 4, 5)

b)

syntax error

c)

(1, 2, 3, 4, 5)

d)

('1', '2', '3', '4', '5')