Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

lists in python

Total questions: 28

Worksheet time: 13mins

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.

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

3.

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

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

Is this the correct code for a list?

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

a)

Yes

b)

No

6.

Consider this list, what will be the highest index the list can have:

li=[1,2,3,4,5]

a)

2

b)

3

c)

4

d)

5

7.

The count() method returns the number of times the specified element appears in the list.

What is the output of this code?

a)

3

b)

2

c)

1

d)

0

8.

Output of this code?

a)

[2,4,6,8,10]

b)

['2','4','6','8','10']

c)

[0,2,4,6,8]

d)

[10,8,6,4,2]

9.

What is the output of this code?

a)

X

b)

Y

c)

Error

10.

Which of the following function is used to count the number of elements in a list ?

a)

count( )

b)

find( )

c)

len( )

d)

index( )

11.

What is the index of “grape” in the list

[“apple”, “grape”, “orange”, “watermelon”]?

a)

0

b)

1

c)

2

d)

3

12.

mylist = ["a","b"]

mylist[1] = "c"'

print(mylist)

a)

["a","c"]

b)

["a","b"]

c)

["a","b","c"]

d)

mylist

13.

What would the output of the program be?

thisList = ["square", "circle", "triangle", "octagon"]

if "triangle" in thisList:

print("Yes, 'triangle' is in the list")

else:

print("No triangle here!")

a)

Yes, 'triangle' is in the list

b)

"No triangle here!"

14.

What is the output of program below?


bicycles = ['trek', 'cannondale', 'redline', 'specialized']

print(bicycles[-1])

a)

trek

b)

cannondale

c)

redline

d)

specialized

15.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed

16.

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"

17.

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

18.

Each item in a list has an "address" or index. The first index in a Python list is what?

a)

1

b)

0

c)

a

d)

A

19.

Which of these codes is correct for creating a list of numbers?

a)

num = ('10','29','37','109')

b)

num = ['10','29','37','109']

c)

num == ('10','29','37','109')

d)

num = ['10 29 37 109']

20.

What is the index number for 'Spain'?

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

a)

0

b)

1

c)

2

d)

3

21.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

22.

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

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

23.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

24.

variable.sort() will do what?

a)

Sort the list into alphabetical order

b)

Sort the list into reverse order

c)

Create a new list

d)

Error

25.

____________function can be used to insert an element/object at a specified index.

a)

extend( )

b)

insert ( )

c)

append( )

26.

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)

27.

nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]

nameList[6] ="Susie"

print(nameList)

What would be the output

a)

['John', 'Harry', 'Jesse', 'John', 'Marry', 'Larry', 'Susie']

b)

['Susie', 'John', 'Harry', 'Jesse', 'John', 'Marry', 'Larry']

c)

['Susie']

d)

Error

28.

Which function(s) out of the following will increase the length of the list?

a)

insert()

b)

index()

c)

append()

d)

extend()

e)

reverse()