Font size
Worksheetslist in python
Total questions: 15
Worksheet time: 15mins
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]
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
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
aList = [5, 10, 15, 25]
print(aList[::-2])
[15, 10, 5]
[10, 5]
[25, 10]
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
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]
Which of the following will give output as [23,2,9,75] ?
If list1=[6,23,3,2,0,9,8,75]
print(list1[1:7:2])
print(list1[0:7:2])
print(list1[1:8:2])
print(list1[0:8:2])
Sort () function in list by default sort the values in __________
Ascending order
Decending order
Suppose list1 is [1, 3, 2], What is list1 * 2 ?
[2, 6, 4].
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']
Which display correct output from below ?
print(a[-5:-3])
['bar', 'baz']
print(a[4::-1])
['quux', 'baz', 'foo']
None
print(a[2])
['bar']
___________ method adds one list at the end of another list.
extend( )
append( )
insert( )
____________function can be used to insert an element/object at a specified index.
extend( )
insert ( )
append( )
___________method adds a single item to the end of the list.
extend( )
append( )
insert( )
