Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Lists Worksheet Questions

Total questions: 35

Worksheet time: 18mins

Name
Class
Date
1.

What will be the output?
lst = [1, 2] * 2
print(lst)

a)

[1, 2, 1, 2]

b)

[2, 4]

c)

Error

d)

[1, 2, 2, 4]

2.

Which method adds an element at a specific index?

a)

append()

b)

insert()

c)

extend()

d)

add()

3.

What is the result of slicing?
a = [10, 20, 30, 40]
print(a[1:-1])

a)

[20, 30]

b)

[10, 20]

c)

[30, 40]

d)

[20]

4.

What will be the output?
a = [3,1,2]
a.sort()
print(a)

a)

[3,2,1]

b)

[1,2,3]

c)

Error

d)

[2,1,3]

5.

Which creates a list?

a)

(1,2,3)

b)

{1,2,3}

c)

[1,2,3]

d)

<1,2,3>

6.

What does this produce?
x = [1,2,3]
y = x
y.append(4)
print(x)

a)

[1,2,3]

b)

[1,2,3,4]

c)

Error

d)

[4]

7.

Output?
print([1,2,3] + [4,5])

a)

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

b)

[1,2,3,4,5]

c)

(1,2,3,4,5)

d)

Error

8.

Which removes the first matching element?

a)

delete()

b)

remove()

c)

pop()

d)

discard()

9.

Output?
a = [10, 20, 30, 40]
print(a[::-1])

a)

[40,30,20,10]

b)

[10,20,30,40]

c)

Error

d)

[30,20]

10.

What will be printed?
lst = [1, 2, 3]
lst.extend([4, 5])
print(lst)

a)

[1,2,3,4,5]

b)

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

c)

[4,5,1,2,3]

d)

Error

11.

Which creates a tuple?

a)

t = (1,2,3)

b)

t = [1,2,3]

c)

t = {1,2,3}

d)

t = <1,2,3>

12.

Single-element tuple?

a)

(5)

b)

(5,)

c)

[5,]

d)

{5}

13.

Output?
t = (1,2,3)
print(len(t))

a)

2

b)

3

c)

Error

d)

1

14.

Can we add an element to a tuple?

a)

Yes, using append()

b)

Yes, using insert()

c)

No, tuple is immutable

d)

Yes, using update()

15.

What is returned by index()?
t = (1,2,3,2)
print(t.index(2))

a)

1

b)

3

c)

[2]

d)

Error

16.

Output?
t = (1,2,3)
t2 = t + (4,)
print(t2)

a)

(1,2,3)

b)

Error

c)

(1,2,3,4)

d)

(4,1,2,3)

17.

Output of count()?
t = (1, 1, 2, 3)
print(t.count(1))

a)

0

b)

1

c)

2

d)

Error

18.

Which is mutable?

a)

tuple

b)

list

c)

both

d)

none

19.

Which statement defines a dictionary?

a)

d = {}

b)

d = []

c)

d = ()

d)

d = <>

20.

Output?
d = {"a":1}
d["b"] = 2
print(d)

a)

{"a":1}

b)

{"b":2}

c)

{"a":1,"b":2}

d)

Error

21.

Removing an element?

a)

remove()

b)

delete()

c)

pop()

d)

discard()

22.

What types can be dictionary keys?

a)

list

b)

set

c)

tuple

d)

dict

23.

Why can’t lists be keys?

a)

Lists are slow

b)

Lists are mutable and unhashable

c)

Lists are large

d)

Lists store duplicates

24.

What does hashing help with?

a)

Storing values in order

b)

Fast key lookup

c)

Sorting keys

d)

Encrypting data

25.

Output?
d = {"x":10, "y":20}
print(len(d))

a)

1

b)

2

c)

3

d)

Error

26.

Output?
d = {"a":1, "b":2}

a)

Nothing is printed

b)

{"a":1, "b":2}

c)

Error

d)

2

27.

print(d.get("c"))

a)

0

b)

None

c)

Error

d)

"c"

28.

Output?
d = {}
d[1] = "A"
print(d)

a)

Error

b)

{1:"A"}

c)

{"1":"A"}

d)

{}

29.

What is the result?
A = {1,2}
B = {2,3}
print(A | B)

a)

{2}

b)

{1,2,3}

c)

{1}

d)

Error

30.

Intersection?
A = {1,2,3}
B = {2,4}
print(A & B)

a)

{1}

b)

{2}

c)

{1,2,3,4}

d)

{}

31.

Difference?
print({1,2,3} - {2})

a)

{2}

b)

{1,3}

c)

{1,2,3}

d)

{}

32.

Which creates a set?

a)

{1,2,3}

b)

[1,2,3]

c)

(1,2,3)

d)

<1,2,3>

33.

Output?
s = {1,2,3}
s.add(4)
print(s)

a)

{1,2,3}

b)

{4}

c)

{1,2,3,4}

d)

Error

34.

What happens?
s = {1,2,3}
s.remove(5)

a)

{1,2,3,5}

b)

{1,2,3}

c)

KeyError

d)

None

35.

Which is valid set comprehension?

a)

{x for x in range(5)}

b)

[x for x in range(5)]

c)

(x for x in range(5))

d)