Worksheetscomputers
Total questions: 36
Worksheet time: 33mins
What is the output of the following list assignment
aList = [4, 8, 12, 16]
aList[1:4] = [20, 24, 28]
print(aList)
[4, 20, 24, 28, 8, 12, 16]
[4, 20, 24, 28]
Select all the correct options to join two lists in Python
listOne = ['a', 'b', 'c', 'd']
listTwo = ['e', 'f', 'g']
newList = listOne + listTwo
newList = extend(listOne, listTwo)
newList = listOne.extend(listTwo)
newList.extend(listOne, listTwo)
What is the output of the following list function?
sampleList = [10, 20, 30, 40, 50]
sampleList.append(60)
print(sampleList)
sampleList.append(60)
print(sampleList)
[10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60, 60]
[10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60]
both are wrong
In Python, list is mutable
False
True
Which of the following would give an error?
list1=[]
list1=[]*3
list1=[2,8,7]
None of the above
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 names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
What sort of bracket is for lists?
(
<
}
[
For tuples and list which is correct?
List and tuples both are mutable.
List is mutable whereas tuples are immutable.
List and tuples both are immutable.
List is immutable whereas tuples are mutable
Which is a correctly declared tuple?
a = ("orange", "yellow", "red")
a = "orange", "yellow", "red"
a = ["orange", "yellow", "red"]
a = "orangeyellowred"
How would you refer to 3 in the following tuple? c = ((7,5),(5,8),(0,-1),(4,3))
c[0][0]
c(3)
c[8]
c[3][1]
What is the index of the following tuple: y = ()
0
1
There is none. It is an empty tuple
Can you have an empty tuple z = () or an empty string w = []?
yes
no
Select correct ways to create an empty dictionary
sampleDict = {}
sampleDict = dict()
sampleDict = dict{}
Please select all correct ways to empty the following dictionary
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
del student
del student[0:2]
student.clear()
Items are accessed by their position in a dictionary
True
False
Dictionary keys must be immutable
True
False
In Python, Dictionaries are immutable
True
False
________________method removes all items from the particular dictionary.
clear( )
pop( )
del ( )
_________________ method will not only delete the item from dictionary, but also return the deleted value.
del ( )
pop( )
Clear( )
_______________this method deletes the item from the dictionary
pop( )
del( )
clear( )
Mode in the following program to open file for writing in a mode where new data will be added at the end of old data
file =open("poem.txt","__")
r
a
w
x
Choose the correct statement to close a file stream named myfile:
myfile.terminate()
myfile.end()
myfile.close()
myfile.remove()
holds whole numbers
holds a decimal point in a number
holds whole numbers
holds a decimal point in a number
print("Hello world!" * 2)
print(Hello world!)
What is the term for * / + -
Operations
Operators
Operands
Opticals
