wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Computer Science LISTS

Total questions: 18

Worksheet time: 10mins

Name
Class
Date
1.

Correct code to define a list in Python?

a)

scores = [15, 29, 4, 50]

b)

scores = {15, 29, 4, 50}

c)

Int[] scores = {15, 29, 4, 50};

d)

scores = (15, 29, 4, 50)

2.

Choose all the ways in which a Python list is different from an array ...

a)

Arrays have fixed length: Lists have dynamic length

b)

Arrays only contain one data type; Lists can contain many data types

c)

Arrays are indexed from 1; Lists are indexed from 0

d)

Arrays can not be empty; Lists can be empty

3.

Output is ...?

a)

mango

b)

pear

c)

kiwi

d)

['apple','banana','pear']

4.

Choose three valid methods that may be applied to lists in Python ...

a)

list.append(x)

b)

list.count(x)

c)

list.sort()

d)

list.format()

e)

list.isNumeric()

5.

colours = ['red', 'blue', 'yellow', 'green', 'purple']


Which instruction illustrates mutability?

a)

colours[2] = 'pink'

b)

colours.append('pink')

c)

colours.insert(2, 'pink')

d)

colours.remove('pink')

6.

Output is ... ?

a)

Index out of range

b)

29

c)

34

d)

89

7.

Correct code to access the second 'Terry' in this list ... ?

a)

montyPython[5]

b)

montyPython[6]

c)

montyPython[-1]

d)

montyPython[3]

8.

Example of ... ?

a)

Indexing

b)

Appending

c)

Slicing

d)

Concatenation

9.

Example of ... ?

a)

Concatenating

b)

Slicing

c)

Indexing

d)

Iterating

10.
for(int i=0; i<10; i++)
           numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
a)
1
b)
2
c)
3
d)
4
11.
What output will this code produce?
a)
red
b)
['blue', 'green', 'red']
c)
['red', 'green', 'blue']
d)
error
12.

What is the output of the following list operation

aList = [10, 20, 30, 40, 50, 60, 70, 80]

print(aList[2:5])

print(aList[:4])

print(aList[3:])

a)

[20, 30, 40, 50]

[10, 20, 30, 40]

[30, 40, 50, 60, 70, 80]

b)

[30, 40, 50]

[10, 20, 30, 40]

[40, 50, 60, 70, 80]

c)

None of these

13.

What is the output of the following

aList = [5, 10, 15, 25]

print(aList[::-2])

a)

[15, 10, 5]

b)

[10, 5]

c)

[25, 10]

14.

What will be the output of below Python code?

list1=[8,0,9,5]


print(list1[::-1])

a)

[5,9,0,8]

b)

[8,0,9]

c)

[8,0,9,5]

d)

[0,9,5]

15.

___________method adds a single item to the end of the list.

a)

extend( )

b)

append( )

c)

insert( )

16.
What does the term 'debug' mean?
a)
Identify errors and fix them.
b)
Making a calculation
c)
A set of instructions
d)
Looking at code
17.

For the code shown, what will happen?

a)

It will print all the numbers from 0 to 11

b)

It will print all the numbers from 0 to 11 in increments of 3

c)

Infinite loop

d)

It will not run (Syntax error)

18.

What will this code output?

a)

Nothing

b)

1

4

7

Bye

c)

Jon

Jon

Bye

d)

Jon

Jon

Jon

Bye

e)

Jon

Jon

Jon

Jon

Jon

Jon

Bye