wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python List Operations 2

Total questions: 100

Worksheet time: 53mins

Name
Class
Date
1.

What is the output of the following code?
L = [10, 20, 30, 40, 50]
result = L[-4:4:2]
print(result)

a)

[20, 40]

b)

[20, 30, 40]

c)

[30]

d)

[20]

2.

What is the result of len(L) after the following operations?
L = [1, 2] * 3
L = L + [4, 5]

a)

6

b)

7

c)

8

d)

5

3.

What is the output? Python ?
L = [1, 2, 3]
L[1:3] = [9, 8, 7, 6]
print(L)

a)

[1, 9, 8, 7, 6]

b)

[1, 9, 8, 7, 6, 4]

c)

[1, 9, 8, 7, 6, 3]

d)

Error

4.

What is the output?
L = ['a', 'b', 'c', 'd']
L[-1] = L[0]
print(L)

a)

['a', 'b', 'c', 'a']

b)

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

c)

['d', 'b', 'c', 'd']

d)

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

5.

L = [10, 20, 30, 40]
What is the output of L[-1] + L[-2]?

a)

70

b)

60

c)

50

d)

30

6.

L = ['a', 'b', ['x', 'y', 'z']]
What is the result of 'z' in L?

a)

True

b)

False

c)

Error

d)

Depends on Python version

7.

What is the output?
L = [10, 20, 30, 40]
print(L[-2:])

a)

[30, 40]

b)

[20, 30, 40]

c)

[40]

d)

[10, 20]

8.

What is the output?
L = [1, 2, 3, 4]
L[0:0] = [99]
print(L)

a)

A: [99, 1, 2, 3, 4]

b)

B: [1, 2, 3, 4]

c)

C: [ ]

d)

D: [99]

9.

L = [1, 2, 3, 4, 5]
What is the value of sum(L) + max(L)?

a)

15

b)

20

c)

18

d)

25

10.

What is the output?
L = [1, 2, 3]

del L[::2]

print(L)

a)

A: [2]

b)

B: [2, 4]

c)

C: [1, 3]

d)

D: Error

11.

What is the final value of result?
L = [10, 20, 30, 40, 50, 60]

result = L[1:5][::-2]

a)

[20, 40]

b)

[60, 40, 20]

c)

[50, 30]

d)

[10, 30, 50]

12.

Which operation results in a list containing [5, 5, 5, 5, 5]?

a)

[5] * 4

b)

[5 + 5 + 5 + 5 + 5]

c)

list(5, 5, 5, 5, 5)

d)

[5] + [5] * 3

13.

What is the calculated value of result?
L = [1, 2, 3, 4, 5]

result = L[1::2][0] * L[::-1][1]

a)

6

b)

8

c)

10

d)

Error

14.

What is the output?
L = [1, 2, 3, 4, 5]

result = L[2:2] + L[3:2:-1] + L[5:5]

print(result)

a)

[]

b)

[4]

c)

[3,4]

d)

4

15.

Which of the following will create a shallow copy of L?

a)

L2 = L

b)

L2 = L.copy()

c)

L2 = list(L)

d)

Both B and C

16.

What is the output?
L = [1, 2, 3]
L[1] = L[1] + 5
print(L)

a)

[1, 7, 3]

b)

[1, 2, 3, 5]

c)

[7]

d)

Error

17.

What is the final value of L after execution?
L = [1, 2, 3]

L = [x * 2 for x in L]

L.pop(1)

L.insert(1, 7)

a)

[2, 4, 6, 7]

b)

[2, 6]

c)

[2, 7, 6]

d)

[1, 7, 3]

18.

What is the output?
L = ['a', 'b']
L = L * 2
print(L)

a)

['a', 'b', 'a', 'b']

b)

['a', 'b']

c)

['aa', 'bb']

d)

['a', 'b'] * 2

19.

What is the final value of L?

a)

100

b)

[99, 2]

c)

[100]

d)

[99,100]

20.

Which statement is true about lists in Python?

a)

Lists can only hold elements of the same data type.

b)

Lists are immutable.

c)

List indexing always starts from 1.

d)

Lists are heterogeneous and mutable.

21.

What is the output?
L = list(range(5))
result = L[::3]
print(result)

a)

[0, 3]

b)

[0, 1, 2, 3, 4]

c)

[0, 4]

d)

[3, 0]

22.

What is the output?
L = [10, 20, 30]

L[2:] = []

print(L)

a)
[10, 20]
b)

[10, 20, []]

c)

[10, 20, 30]

d)

[30]

23.

What is the output ?

a)

[]

b)

Other

c)

Index

d)

Error

24.

What is the output?

L = [10, 20]

L += (30, 40)

print(L)

a)

[10, 20, 30, 40]

b)

[10, 20, (30, 40)]

c)

Error, cannot add list and tuple.

d)

[10, 20, 70]

25.

What is the output?
L = [10, 20, 30]
result = L[1:-1]

a)

[20, 30]

b)

[10, 20]

c)

[20]

d)

[]

26.

What is the output?
L = [1, 2, 3, 4, 5]
L[4:1:-1] = [9, 8, 7]
print(L)

a)

[1, 2, 7, 8, 9]

b)

[1,2, 9, 8, 7]

c)

Error: slice assignment cannot be used with step.

d)

[1, 7, 8, 9, 5]

27.

What is the output of L?
T = (1, 2, [3, 4])

L = list(T)

L[2].append(5)
print(L)

a)

[1, 2, [3, 4]]

b)

(1, 2, [3, 4, 5])

c)

[1, 2, [3, 4, 5]]

d)

Error as Tuple immutable

28.

If L = [1, 2, 3], what is L * 0?

a)

[0, 0, 0]

b)

[1, 2, 3]

c)

[]

d)

Error

29.

What is the result of L.count(1)?
L = [1, [1], 1, [1, 1]]

a)

1

b)

2

c)

3

d)

4

30.

What is the final value of L?
L = [1, 2, 3, 4]

L[::] = sorted(L, reverse=True)

print(L)

a)

[3, 2, 1]

b)

[4, 3, 2, 1]

c)

[4, 3, 2]

d)

[]

31.

Find the output?

a)

[1, 2, 3, 4, 5]

b)

[2, 3, 4, 5, 6]

c)

15

d)

[1, 2, 3, 4, 5, 1, 1, 1, 1, 1]

32.

Which slice reverses the list L?

a)

L[:-1]

b)

L[:1:-1]

c)

L[::-1]

d)

L.reverse()

33.

L = [1, 2, 3]
del L[1]
print(L)

a)

[1, 3]

b)

[2, 3]

c)

[1, 2]

d)

[3]

34.

L = [5, 'a']
What is the result of min(L)?

a)

5

b)

'a'

c)

'5'

d)

Error (unorderable types)

35.

Which statement about list traversal is incorrect?

a)

You can use a for loop to iterate over elements.

b)

You can use a while loop with an index to traverse.

c)

A for loop is generally faster than a while loop for simple traversal.

d)

The for i in L: loop provides access to the index of each element.

36.

L = [10, 20]
L *= -1
print(L)

a)

[10, 20, 10, 20]

b)

[10, 20, -10, -20]

c)

Error

d)

[]

37.

What is the output?
L = [10, 20, 30, 40]

del L[1::2]

print(L)

a)

[10, 20, 30]

b)

[10, 30]

c)

[20, 40]

d)

[10, 40]

38.

List=[1,2]
K=List.append(3)
What is the return value of the append() method?

a)

[1, 2, 3]

b)

3

c)

None

d)

[1,2]

39.

What is the output?
L = [1, 2]
L.append([3, 4])
print(len(L))

a)

4

b)

3

c)

2

d)

Error

40.

What is the difference between L.append(x) and L.extend(x)?

a)

append adds one element; extend adds multiple elements.

b)

append modifies the original list; extend returns a new list.

c)

append adds the element as a single item; extend adds elements of the iterable separately.

d)

extend only works with other lists; append works with any data type.

41.

What is the output?
L = [1, 2]
L.extend('abc')
print(L)

a)

[1, 2, 'abc']

b)

[1, 2, ['a', 'b', 'c']]

c)

[1, 2, 'a', 'b', 'c']

d)

Error

42.

Q40: What is the output of the following Python code?
L = [1, 2, 3]

L.insert(10, 4)

print(L)

a)

[1, 2, 3]

b)

[1,2,3,0,4]

c)

[1, 2, 3, 4]

d)

Error

43.

What is the value of L1[0] + L2[0]?

a)

5

b)

6

c)

4

d)

Error

44.

What is the output ?
L = [10, 20, 30]
result = L.pop()
print(result, L)

a)

A: 30 [10, 20]

b)

B: [10, 20] 30

c)

C: None [10, 20]

d)

D: Error

45.

What happens if L.pop(10) is called on a list of size 3?

a)

It removes the last element.

b)

It returns None.

c)

It raises an IndexError.

d)

It removes the first element.

46.

What is the output?
L = [1, 2, 3, 2]
L.remove(2)
print(L)

a)

[1, 3, 2]

b)

[1, 3]

c)

[1, 2, 3]

d)

[1,2,2]

47.

What is the return value of L.remove(2)?

a)

The element removed (2)

b)

The modified list

c)

None

d)

Error

48.

What is the output?
L = [10, 20, 30]
L=L.reverse()
print(L)

a)

[30, 20, 10]

b)

[10, 20, 30]

c)

None

d)

Error

49.

What is the difference between L.reverse() and L[::-1]?

a)

reverse() modifies the list in-place; L[::-1] returns a new reversed list.

b)

reverse() is for strings; L[::-1] is for lists.

c)

reverse() returns a new list; L[::-1] modifies the list in-place.

d)

No difference, they are equivalent.

50.

What is the output?

a)

[1, 2, 3]

None

b)

None
None

c)

Error

d)

None
[1,2,3]

51.

What is the difference between L.sort() and sorted(L)?

a)

sort() returns a new sorted list; sorted() modifies the list in-place.

b)

sort() works on lists only; sorted() works on any iterable.

c)

sort() creates a shallow copy; sorted() creates a deep copy.

d)

sorted() is faster than sort().

52.

What is the output?
L = [30, 10, 20]

result = sorted(L, reverse=True)

print(result)

a)

[30, 20, 10]

b)

[10, 20, 30]

c)

None

d)

[30, 10, 20]

53.

What is the output?
L = [1, 2, 3, 4]
L.insert(2, L.pop(1))
print(L)

a)

[1, 3, 2, 4]

b)

[1, 2, 3, 4]

c)

[1, 2, 2, 3, 4]

d)

Error

54.

What is the output?
L = [10, 20, 30, 40]

L[1:3] = [L.pop(0)]

print(L)

a)

[10,20, 10]

b)

[10, 10]

c)

[20, 10]

d)

[10, 10,30,40]

55.

What is the output?
L = list(range(10))

result = L[1:100:10]

print(result)

a)

[1]

b)

[1,10]

c)

[]

d)

[1,9]

56.

What is the output ?

L = [10, 20, 30, 20, 50]

L.insert(L.index(20, 2),40)

print(L)

a)

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

b)

[10, 20, 30, 40, 50]

c)

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

d)

D: Error

57.

If L.count(x) returns 0, which statement is guaranteed to raise a ValueError?

a)

L.pop(x)

b)

L.remove(x)

c)

L.index(x)

d)

L.insert(0, x)

58.

What is the output?
L = [10, 20, 30]
L.append(L.pop(0))
print(L)

a)

[10, 20, 30]

b)

[20, 30, 10]

c)

[20, 30]

d)

[30, 20, 10]

59.

Which of the following correctly appends a tuple (1, 2) as a single element?

a)

L.extend((1, 2))

b)

L.append(1, 2)

c)

L.append((1, 2))

d)

L + (1, 2)

60.

What is the output?
L = [1, 2, 3]
L[::2] = [10, 30]
print(L)

a)

[10, 2, 30]

b)

[10, 2, 30, 4]

c)

Error: must assign iterable of same length.

d)

[1, 2, 3, 10, 30]

61.

What is the output?
L = [1, 2, 3]
L.insert(-1, 9)
print(L)

a)

[9, 1, 2, 3]

b)

[1, 9, 2, 3]

c)

[1, 2, 9, 3]

d)

[1, 2, 3, 9]

62.

Which method is used to remove an item by its value?

a)

pop()

b)

index()

c)

remove()

d)

del

63.

What is the output of L.pop(-1)?
L = [10, 20, 30]

a)

10

b)

20

c)

30

d)

Error

64.

What is the output?
L = [1, 2, 3]
L[3:3] = [4, 5]
print(L)

a)

A: [1, 2, 3, 4, 5]

b)

B: Error (Index out of range)

c)

C: [4, 5, 1, 2, 3]

d)

D: [1, 2, 3, [4, 5]]

65.

What does list(S) do, where S = 'Python'?

a)

Creates a list ['P', 'y', 't', 'h', 'o', 'n'].

b)

Creates a list ['Python'].

c)

Creates a list of ASCII values.

d)

Raises an error.

66.

What is the output?
L = [1, 2, 3]

L[::2] = [9]

print(L)

a)

[1,2,9]

b)

[9, 2, 9]

c)

[1, 9, 9]

d)

ValueError:

67.

How can you empty a list L most efficiently?

a)

L.clear()

b)

L = []

c)

del L[:]

d)

All of the above

68.

What is the output?

a)

[1,7,3]

b)

[2,4,7,6]

c)

[2,7,6]

d)

[1,2,3,1]

69.

Which method returns the number of times a value appears?

a)

index()

b)

count()

c)

len()

d)

sum()

70.

What is the output?

a)

[1, 2, 3]

b)

[1, 2, 3, 0]

c)

[3, 1, 2]

d)

Error

71.

What is the output?
L = [1, 2, 3, 4, 5]

result = L[2:2] + L[3:2:-1] + L[4:4]

print(result)

a)

11

b)

[11]

c)

[4]

d)

4

72.

What is the output of the following Python code?
L = [1, 2, 3]
L = L.reverse()
print(L)

a)

[3, 2, 1]

b)

[1, 2, 3]

c)

None

d)

Error

73.

What is the output of min(L)?
L = [1, [2, 3], 4]

a)

A: 1

b)

B: 2

c)

C: [2, 3]

d)

D: Error

74.

What is the output?
L = [10, 20, 30]

result = (L.append(40) is None) and (L.pop(0) == 10)

print(result)

a)

[20, 30, 40]

b)

True

c)

False

d)

Error

75.

What is the output?
L = [1, [2, 3], 4]
L[1][0] = 99
print(L)

a)

[1, [99, 3], 4]

b)

[1, 99, 4]

c)

Error

d)

[1, [2, 3], 4]

76.

What is the output?
L = [1, 2, 3]
result = L[::2][::-1]
print(result)

a)

[1,3]

b)

[1, 2]

c)

[1, 2, 3]

d)

[3, 1]

77.

What is the output?
L = [1, 2, 3, 4, 5, 6]

result = L[1::2][-1::-1][::2]

print(result)

a)

[6, 4, 2]

b)

[6, 2]

c)

[6, 4]

d)

[5, 3]

78.

What is the output?
L = [1, 2, 3, 4, 5]

L[1:4] = L[4:1:-1]

print(L)

a)

[1, 5, 4, 3, 5]

b)

[1, 5, 4, 3, 5, 6]

c)

[1, 5, 4, 3,6]

d)

Error: target slice length must match assignment length.

79.

Find the output?

a)

31

b)

21

c)

36

d)

26

80.

What is the output?
L = [[1], 2, 3]

L2 = L.copy()

L2[0][0] = 99

print(L)

a)

[[1], 2, 3]

b)

[[99], 2, 3]

c)

[[99], 1, 2]

d)

[[1], 99, 3]

81.

What is the output?

a)

[1, 2, [3, 4]]

b)

[1, 2, [3, 4, 5]]

c)

[1, 99, [3, 4]]

d)

[1, 99, [3, 4, 5]]

82.

What is the output?
L = [1, 2, 3]

L[4:4] = [5]

print(L)

a)

[1,2,5]

b)

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

c)

[1,2,3,5]

d)

Error

83.

What is the result of L[-10:] when L is a list of 5 elements?

a)

Error

b)

The last element

c)

[]

d)

The whole list

84.

What is the final value of L1?

a)

[1, 2, 3]

b)

[1, 2, 3, 4]

c)

None

d)

Error

85.

What is the final value of L1?

a)

[1, 2, 3]

b)

[5, 6, 7]

c)

None

d)

Error

86.

What is the final value of L1?

a)

[1, 2, 3]

b)

[99, 2, 3]

c)

[100]

d)

[99, 100]

87.

What is the output?
L = [1, 2, 3]
L[2::-2] = [9, 8]
print(L)

a)

[5, 1, 2, 3]

b)

[1, 2, 3, 5]

c)

[8, 2, 9]

d)

[1, 2, 3, 4, 5]

88.

What is the output?
L = [1, 2, 3, 4]

result = L[:0]

print(result)

a)

[]

b)

[1, 2, 3, 4]

c)

Error

d)

[1]

89.

What is the output?

a)

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

b)

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

c)

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

d)

[2, 3, 4, 2, 3, 4]

90.

What is the output?
L = [1, 2, 3, 4, 5]

del L[L[0] : L[3]]

print(L)

a)

[]

b)

[5]

c)

[2,3,4]

d)

[1, 5]

91.

L = [1, 2, 3, 4, 5]
Which slice expression results in [3, 2]?

a)

L[2::-1][1:3]

b)

L[2:0:-1]

c)

L[2:0:-2]

d)

L[2:1:-1]

92.

What is the output?
L = [1, 2]
L[1:1] = L
print(L)

a)

[1, 1, 2, 2]

b)

[1, 2, 1, 2]

c)

[1, 2]

d)

Error

93.

What is the output?
L = [1, 2, 3, 4, 5]

result = L[L[1] + 1 : L[2] + 2]

print(result)

a)

[3, 4, 5]

b)

[3, 4]

c)

[4, 5]

d)

[2, 3, 4]

94.

What is the final calculated value of result ?
L = [1, 2, 3, 4, 5]

result = L[1::2][0] * L[::-1][1]

a)

6

b)

8

c)

10

d)

12

95.

What is the output?
L = [1, 2, 3]

L2 = L.copy()

L.remove(2)

print(L2)

a)

[2, 3]

b)

[1, 2, 3]

c)

[1, 3]

d)

[1,2,1,2]

96.

What is the output?
L = [10, 20]

L.insert(-1, [30, 40])

print(L)

a)

[10, [30, 40], 20]

b)

[[30, 40], 10, 20]

c)

[10, 30, 40, 20]

d)

[10, 20, [30, 40]]

97.

What is the output?
L = [1, 2, 3, 4]

del L[::2]

print(L)

a)

[4, 2]

b)

[1, 3]

c)

[2, 4]

d)

Error

98.

What is the output?
L = [[1, 2], 3]

L2 = list(L)

L2[0].append(4)

print(L)

a)

[[1, 2], 3]

b)

[[1, 2, 4], 3]

c)

[[1, 2, 4], 3]

d)

Error

99.

What is the final value of L?

a)

[1, 2, 3]

b)

[100]

c)

[2, 2, 3]

d)

[2, 100]

100.

What is the value of L1?

a)

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

b)

[[99], [3, 4, 5]]

c)

[[1, 2, 5], [3, 4]]

d)

[[1, 2], [3, 4, 5]]