NEW
Font size
WorksheetsList, Tuples, & Slicing Review 2024
Total questions: 40
Worksheet time: 42mins
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
Which of these is the correct code for creating a list of numbers?
numList = 1, 2, 3, 4, 5, 6
numList = (1, 2, 3, 4, 5, 6)
numList = [1, 2, 3, 4, 5, 6]
numList = [1 2 3 4 5 6]
Which of these is the correct code for creating a list of names?
nameList = Juan, Aaron, Rosario, John, Irvin, Selina
nameList = ("Juan", "Aaron", "Rosario", "John", "Irvin", "Selina")
nameList = ["Juan", "Aaron", "Rosario", "John", "Irvin", "Selina"]
nameList = [Juan, Aaron, Rosario, John, Irvin, Selina]
List items have an index number. In the following list, which item has the index number of 3?
["Juan", "Aaron", "Rosario", "John", "Irvin", "Selina"]
"John"
"Juan"
"Rosario"
"Irvin"
What would this code show on the screen?
7
6
5
4
An error
print (people[-1])
What would this result be?
What would this code print to the console?
Nothing will print to the console
An error will print to the console
"Woo hoo, you scored!"
"Raheem"
Zoe is learning about lists and tuples in Python. She knows that one of them is mutable and the other is immutable. James and Ava are having a debate about this. Which of the following statements is correct?
James says that both lists and tuples are mutable.
Ava says that lists are mutable whereas tuples are immutable.
James says that both lists and tuples are immutable.
Ava says that lists are immutable whereas tuples are mutable.
What is the output of the program above
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
If list1=[17,23,41,10]
then list1.append(32) will result in:
[32,17,23,41,10]
[17,23,41,10,32]
[10,17,23,32,41]
[41,32,23,17,10]
If list2=[5,9,12,20,15]
then list2.sort() will result in:
[15, 5, 9, 12, 20]
[5, 9, 12, 15, 20]
[15, 20, 12, 9, 5]
word = "amazing"
For the given string if we run word[2:5] what does it mean?
It will extract alphabets from index 2 to index 4
It will extract alphabets from index 2 to index 5
It will extract alphabets from position 2 to position 4
It will extract alphabets from position 2 to position 5
If a tuple and list contain identical values which datatype is larger in size when the computer creates it and allocate memory for it?
my_list=[5,9,12,20,15]
my_tuple=(5,9,12,20,15)
Tuple
List
both will have the same memory space allocation since they are identical.
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
alpha = 'abcdef'
alpha[0:3]
'abc'
'abcd'
'abcde'
none
What is the purpose of index 0 in a list?
To access the first item
To access the second item
To access the last item
To access the item at index 1
alpha = 'abcdef'
alpha[0:4]
'ab'
'abc'
'abcd'
Which brackets are used for Lists?
( )
[ ]
{ }
None of the above
alpha = 'abcdef'
alpha[2:4]
'cd'
b'cd'
'abcd'
'cde'
When we create a program to extract each alphabet from a given string, what is it known as?
Transpose
Traverse
Translate
Terminate
alpha = 'abcdef'
alpha[2:]
'cdf'
'ef'
'def'
'cdef'
Function used to add element in to List?
Add( )
append( )
update( )
alpha = 'abcdef'
alpha[0:6:2]
'ace'
'abce'
'acde'
'ce'
What is the output of program below?
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles[-1])
trek
cannondale
redline
specialized
What is the output of the program below?
cars = ['audi', 'bmw', 'mercedes', 'tesla']
print(cars[-2])
audi
bmw
mercedes
tesla
For example:
numbers = [ [1, 2, 3, 4], [2, 4, 6, 8], [3, 6, 9, 12]]
print(numbers[2][1]) refers to .......................
1
2
6
Which of the following statements is true about a 2D list in Python?
It is a single list with two elements.
It is a list of dictionaries.
It is a list of lists.
Which would be the correct code to access number 10
list_2d[3][4]
list_2d= [2,3]
list_2d[2][3]
list_2d(0,0)
In which order are the numbers?
[row][column]
[column][row]
What name would be printed with the code print(names[1][1])
Jim
Sarah
Bob
John
cars=["mini", "VW", "BMW"]
x = len(cars)
print(x)
What will the above code print?
mini,VW,BMW
2
9
3
A two-dimensional array Array_2d consists of data: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]. What is the output of print(Array_2d[1][1])?
1
2
5
6
What would be returned with the code print([2][1]
Index out of range
Bob
John
Jim
What will be the output for the program above?
[15, 7, 95]
15
35
7
What will be the output for the program above?
[15, 7, 95]
15
95
7
35
What will be the output for the code above?
[4,35,[15,7,95]]
[4,35,[15,7,95],[21,47]]
[4, 35, 15, 7, 95, 21, 47]
[4, 35, [15, 7, 95], 21, 47]
What will be the output for the program above?
[[78,86,100,97],100,60,70,95]
[100, 60, 70, 95, [78, 86, 100, 97]]
[100, 60, 70, 95, 78, 86, 100, 97]
What does this program print?
[48, 56, 64, 65, [60, 61, 62]]
[48, 56, 60, 61, 62, 64, 65]
[48, 56, 64, 65, 60, 61, 67]
[48, 56, 64, 65, 60, 61, 62]
