Font size
WorksheetsPython Lists and Tuples Review
Total questions: 20
Worksheet time: 10mins
which of the following best describes a list in Python?
a collection of characters
a collection that groups related values
a type of function
a mathematical operation
How do you define a list in Python?
{ }
( )
[ ]
< >
You can access list elements using an index. What index number is used for the first element?
1
-1
0
it depends on the list
What kind of loop can we use to iterate through a list?
for loop
while loop
neither
for loop or while loop
Which for loop header will loop through the list values?
(assume I have a list variable names)
for x in name
for x in range(len(name)
for names
for x in len(name)
Which for loop header will iterate through the list indices?
(assume I have a list variable names)
for x in names
for x in range( len(names)
for names
for x in len(names)
Lists are mutable. This means...
You cannot change them once they are created
They can only hold a limited number of elements
They cannot be looped through
You can change elements without recreating the list
(True/False) Strings are immutable, while lists are mutable.
true
false
Which operator concatenates two lists.
/
+
*
&
The expression [1, 2] * 2 results in what?
[2, 4]
[ [1, 2], [1, 2] ]
[1, 2, 1, 2]
[1, 1, 2, 2]
Which list method adds an item to the end?
.insert()
.pop()
.cut()
.append()
What will the code my_list.pop(2) do?
remove the first instance of the value 2 from my_list
remove the element at index 2 from my_list
remove all instances of the value 2 from my_list
remove the first two elements from my_list
Which of these options will modify the original list of my_list?
sorted(my_list)
len(my_list)
my_list.count()
my_list.sort()
Which of these returns a copy of the list rather than modifying it directly?
.sort()
sorted()
.reverse()
.append()
What does adding reverse=True as an argument do in .sort() ?
Sorts alphabetically
Sorts from highest to lowest
Removes duplicates
Sorts randomly
Which argument can we add to .sort() or sorted() that allows us to customize how elements are compared before sorting?
mod
order
key
compare
Which of these symbols is used to define a tuple ?
[ ]
( )
{ }
< >
Tuples are .....
mutable
immutable
Which of the following can be used with a tuple?
.count()
.append()
.sort()
.remove()
Which of the following is true about list comprehension?
it is used to apply a modification to an existing list
it is used to create a new list given an existing collection
it is not a valid way to create a list
the order in which we place its three components matters
