Font size
WorksheetsComputer Science LISTS
Total questions: 18
Worksheet time: 10mins
Correct code to define a list in Python?
scores = [15, 29, 4, 50]
scores = {15, 29, 4, 50}
Int[] scores = {15, 29, 4, 50};
scores = (15, 29, 4, 50)
Choose all the ways in which a Python list is different from an array ...
Arrays have fixed length: Lists have dynamic length
Arrays only contain one data type; Lists can contain many data types
Arrays are indexed from 1; Lists are indexed from 0
Arrays can not be empty; Lists can be empty
Output is ...?
mango
pear
kiwi
['apple','banana','pear']
Choose three valid methods that may be applied to lists in Python ...
list.append(x)
list.count(x)
list.sort()
list.format()
list.isNumeric()
colours = ['red', 'blue', 'yellow', 'green', 'purple']
Which instruction illustrates mutability?
colours[2] = 'pink'
colours.append('pink')
colours.insert(2, 'pink')
colours.remove('pink')
Output is ... ?
Index out of range
29
34
89
Correct code to access the second 'Terry' in this list ... ?
montyPython[5]
montyPython[6]
montyPython[-1]
montyPython[3]
Example of ... ?
Indexing
Appending
Slicing
Concatenation
Example of ... ?
Concatenating
Slicing
Indexing
Iterating
numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
What is the output of the following list operation
aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:])
[20, 30, 40, 50]
[10, 20, 30, 40]
[30, 40, 50, 60, 70, 80]
[30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]
None of these
What is the output of the following
aList = [5, 10, 15, 25]
print(aList[::-2])
[15, 10, 5]
[10, 5]
[25, 10]
What will be the output of below Python code?
list1=[8,0,9,5]
print(list1[::-1])
[5,9,0,8]
[8,0,9]
[8,0,9,5]
[0,9,5]
___________method adds a single item to the end of the list.
extend( )
append( )
insert( )
For the code shown, what will happen?
It will print all the numbers from 0 to 11
It will print all the numbers from 0 to 11 in increments of 3
Infinite loop
It will not run (Syntax error)
What will this code output?
Nothing
1
4
7
Bye
Jon
Jon
Bye
Jon
Jon
Jon
Bye
Jon
Jon
Jon
Jon
Jon
Jon
Bye
