wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

list in python

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.

What is the output of the following list assignment

aList = [4, 8, 12, 16]

aList[1:4] = [20, 24, 28]

print(aList)

a)

[4, 20, 24, 28, 8, 12, 16]

b)

[4, 20, 24, 28]

2.

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:])

a)

[20, 30, 40, 50]

[10, 20, 30, 40]

[30, 40, 50, 60, 70, 80]

b)

[30, 40, 50]

[10, 20, 30, 40]

[40, 50, 60, 70, 80]

c)

None of these

3.

Select all the correct options to join two lists in Python

listOne = ['a', 'b', 'c', 'd']

listTwo = ['e', 'f', 'g']

a)

newList = listOne + listTwo

b)

newList = extend(listOne, listTwo)

c)

newList = listOne.extend(listTwo)

d)

newList.extend(listOne, listTwo)

4.

What is the output of the following

aList = [5, 10, 15, 25]

print(aList[::-2])

a)

[15, 10, 5]

b)

[10, 5]

c)

[25, 10]

5.

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)

a)

[10, 20, 30, 40, 50, 60]

[10, 20, 30, 40, 50, 60, 60]

b)

[10, 20, 30, 40, 50, 60]

[10, 20, 30, 40, 50, 60]

c)

both are wrong

6.

In Python, list is mutable

a)

False

b)

True

7.

Which of the following would give an error?

a)

list1=[]

b)

list1=[]*3

c)

list1=[2,8,7]

d)

None of the above

8.

What will be the output of below Python code?

list1=[8,0,9,5]


print(list1[::-1])

a)

[5,9,0,8]

b)

[8,0,9]

c)

[8,0,9,5]

d)

[0,9,5]

9.

Which of the following will give output as [23,2,9,75] ?

If list1=[6,23,3,2,0,9,8,75]

a)

print(list1[1:7:2])

b)

print(list1[0:7:2])

c)

print(list1[1:8:2])

d)

print(list1[0:8:2])

10.

Sort () function in list by default sort the values in __________

a)

Ascending order

b)

Decending order

11.

Suppose list1 is [1, 3, 2], What is list1 * 2 ?

a)

[2, 6, 4].

b)

[1, 3, 2, 1, 3]

c)

[1, 3, 2, 1, 3, 2]

d)

[1, 3, 2, 3, 2, 1]

12.

a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']

Which display correct output from below ?

a)

print(a[-5:-3])

['bar', 'baz']

b)

print(a[4::-1])

['quux', 'baz', 'foo']

c)

None

d)

print(a[2])

['bar']

13.

___________ method adds one list at the end of another list.

a)

extend( )

b)

append( )

c)

insert( )

14.

____________function can be used to insert an element/object at a specified index.

a)

extend( )

b)

insert ( )

c)

append( )

15.

___________method adds a single item to the end of the list.

a)

extend( )

b)

append( )

c)

insert( )