wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Lists in Python

Total questions: 20

Worksheet time: 9mins

Name
Class
Date
1.

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]

2.

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"

3.

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

4.

What is the index number for 'Spain'?

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

a)

0

b)

1

c)

2

d)

3

5.

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

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

6.

Why is using lists beneficial?

a)

Shorter Code

b)

More Accurate

c)

It takes less time for the program to run

d)

Its not beneficial

7.

What sort of loop is this?

a)

Count Controlled

b)

Condition Controlled

8.

What is the output of the program below?


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

cmni = mariana_islands[1:]

len(cmni)

a)

1

b)

2

c)

3

d)

4

9.

What would this code do?

a)

Remove the name "Felipe" from the list

b)

Remove the first copy of "John" from the list

c)

Remove the name "Felipe" from the list and print it out to the shell

d)

An error

10.

An empty list can be declared as

a)

fruitList = ""

b)

fruitList = ["empty"]

c)

fruitList == []

d)

fruitList = []

11.

1. A list is ------------------------------ data type

a)

sequence

b)

selection

c)

iteration

d)

None of hese

12.

List need not be always----------------------------------------

a)

Non Homogeneous

b)

Homogeneous

c)

sequence

d)

selective

13.

1. Lists are indexed by an ----------------------------------------------

a)

decimal

b)

neither integer nor dcimal

c)

integer

d)

fraction

14.

1. Lists are ---------------------------------, you can update or edit the list

a)

Immutable

b)

Mutable

c)

Both

d)

None of these

15.

1.In a list elements are enclosed in----------------------------------

a)

square bracket

b)

curly bracket

c)

parenthesis

d)

None of these

16.

-------------------method is used to delete elements from a list if index is not known

a)

pop

b)

push

c)

remove

d)

insert

17.

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

18.

What is the function of the reverse method for lists?

a)

removes the first occurrence of the information inside the parenthesis

b)

adds the information inside the parenthesis to the end of the list

c)

reverses the order of the elements inside a list

d)

sorts the list (lowest to highest for numbers and alphabetical order for strings)

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

To print a list called fruitList we use

a)

print(fruitList)

b)

list(print)

c)

fruitList.print()

d)

fruitList(print)