wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Tuple & Dictionaries

Total questions: 40

Worksheet time: 23mins

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

26.

a= "ICT", "HARDWARE","SOFTWARE", "NETWORK"

which of the following blocks will be used to print "SOFTWARE"

a)

print(a[0])

b)

print(a[1])

c)

print(a[2])

d)

print(a[3])

27.

What is the difference between a list and a tuple?

a)

A list is mutable, while a tuple is immutable

b)

A list can contain different data types, while a tuple can only contain one data type

c)

A list is ordered, while a tuple is unordered

d)

There is no difference

28.

What will be the output of the following code?

my_tuple = (1, 2, 3, 4, 5)

print(my_tuple[1:4])

a)

(2, 3, 4)

b)

(1, 2, 3, 4)

c)

(2, 3, 4, 5)

d)

(1, 2, 3)

29.

What will be the output of the following code?

my_tuple = (1, 2, 3, 4, 5)

print(my_tuple[-2])

a)

1

b)

2

c)

3

d)

4

30.

What will be the output of the following code?

my_tuple = (5, 4, 3, 2, 1)

print(my_tuple[3])

a)

2

b)

3

c)

4

d)

5

31.

Result of the program above is

a)

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

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

32.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

33.

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

34.

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

35.

What is the output of the code above ?

a)

1 4

b)

1

c)

1 None

d)

1 [2,3,4]

e)

1 (2,3,4)

36.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

37.

Which is a correctly declared tuple?

a)

a = ("orange", "yellow", "red")

b)

a = "orange", "yellow", "red"

c)

a = ["orange", "yellow", "red"]

d)

a = "orangeyellowred"

38.

How would you refer to 3 in the following tuple? c = ((7,5),(5,8),(0,-1),(4,3))

a)

c[0][0]

b)

c(3)

c)

c[8]

d)

c[3][1]

39.

Suppose you have the following tuple definition:


t = ('foo', 'bar', 'baz')


Which of the following statements replaces the second element ('bar') with the string 'qux':

a)

t[1] = 'qux'

b)

t(1) = 'qux'

c)

t[1:1] = 'qux'

d)

It’s a trick question—tuples can’t be modified.

40.
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