wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Lists and Tuples Review

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

which of the following best describes a list in Python?

a)

a collection of characters

b)

a collection that groups related values

c)

a type of function

d)

a mathematical operation

2.

How do you define a list in Python?

a)

{ }

b)

( )

c)

[ ]

d)

< >

3.

You can access list elements using an index. What index number is used for the first element?

a)

1

b)

-1

c)

0

d)

it depends on the list

4.

What kind of loop can we use to iterate through a list?

a)

for loop

b)

while loop

c)

neither

d)

for loop or while loop

5.

Which for loop header will loop through the list values?
(assume I have a list variable names)

a)

for x in name

b)

for x in range(len(name)

c)

for names

d)

for x in len(name)

6.

Which for loop header will iterate through the list indices?
(assume I have a list variable names)

a)

for x in names

b)

for x in range( len(names)

c)

for names

d)

for x in len(names)

7.

Lists are mutable. This means...

a)

You cannot change them once they are created

b)

They can only hold a limited number of elements

c)

They cannot be looped through

d)

You can change elements without recreating the list

8.

(True/False) Strings are immutable, while lists are mutable.

a)

true

b)

false

9.

Which operator concatenates two lists.

a)

/

b)

+

c)

*

d)

&

10.

The expression [1, 2] * 2 results in what?

a)

[2, 4]

b)

[ [1, 2], [1, 2] ]

c)

[1, 2, 1, 2]

d)

[1, 1, 2, 2]

11.

Which list method adds an item to the end?

a)

.insert()

b)

.pop()

c)

.cut()

d)

.append()

12.

What will the code my_list.pop(2) do?

a)

remove the first instance of the value 2 from my_list

b)

remove the element at index 2 from my_list

c)

remove all instances of the value 2 from my_list

d)

remove the first two elements from my_list

13.

Which of these options will modify the original list of my_list?

a)

sorted(my_list)

b)

len(my_list)

c)

my_list.count()

d)

my_list.sort()

14.

Which of these returns a copy of the list rather than modifying it directly?

a)

.sort()

b)

sorted()

c)

.reverse()

d)

.append()

15.

What does adding reverse=True as an argument do in .sort() ?

a)

Sorts alphabetically

b)

Sorts from highest to lowest

c)

Removes duplicates

d)

Sorts randomly

16.

Which argument can we add to .sort() or sorted() that allows us to customize how elements are compared before sorting?

a)

mod

b)

order

c)

key

d)

compare

17.

Which of these symbols is used to define a tuple ?

a)

[ ]

b)

( )

c)

{ }

d)

< >

18.

Tuples are .....

a)

mutable

b)

immutable

19.

Which of the following can be used with a tuple?

a)

.count()

b)

.append()

c)

.sort()

d)

.remove()

20.

Which of the following is true about list comprehension?

a)

it is used to apply a modification to an existing list

b)

it is used to create a new list given an existing collection

c)

it is not a valid way to create a list

d)

the order in which we place its three components matters