wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 24

Worksheet time: 12mins

Name
Class
Date
1.

Which method is used to remove a key-value pair from a dictionary?

a)

remove()

b)

pop()

c)

discard()

d)

delete()

2.

Which method adds an item to a list at the end?

a)

insert()

b)

append()

c)

add()

d)

push()

3.

What is the output of ' '.join(['a','b','c'])?

a)

'abc'

b)

'a, b, c'

c)

'a+b+c'

d)

'a b c'

4.

What is the output of the following code? t = (1,2,[3,4]) t[2].append(5) print(t)

a)

(1, 2, [3, 4])

b)

(1, [3, 4, 5])

c)

Error

d)

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

5.

How do you convert a list to a set?

a)

set(list)

b)

tuple(list)

c)

dict(list)

d)

list(set)

6.

What is the output of the following code? stack = [] stack.append(10) stack.append(20) print(stack.pop())

a)

20

b)

10

c)

[]

d)

None

7.

What will `len({})` return?

a)

None

b)

Error

c)

1

d)

0

8.

Which of the following supports LIFO order?

a)

Stack

b)

Queue

c)

List

d)

Dictionary

9.

What is the output of the following code? d = {'a':1, 'b':2} d['a'] += 1 print(d['a'])

a)

'a'

b)

3

c)

2

d)

1

10.

How do you access the first element in a list `a`?

a)

a[0]

b)

a[-1]

c)

a[1]

d)

a.get(0)

11.

Which method adds an item to a list at the end?

a)

add()

b)

insert()

c)

append()

d)

push()

12.

What is the output of the following code? s = {1,2,3,2,1} s.add(4) print(len(s))

a)

6

b)

5

c)

4

d)

3

13.

Which collection type is unordered and does not allow duplicates?

a)

Set

b)

Tuple

c)

Dictionary

d)

List

14.

Which collection allows key-value mapping?

a)

List

b)

Dictionary

c)

Tuple

d)

Set

15.

What does `list('abc')` return?

a)

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

b)

['abc']

c)

('a','b','c')

d)

{'a','b','c'}

16.

What is the output of the following code? t = (1,2,[3,4]) t[2].append(5) print(t)

a)

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

b)

Error

c)

(1, [3, 4, 5])

d)

(1, 2, [3, 4])

17.

What will 'python'[1:4] return?

a)

'tho'

b)

'pyt'

c)

'yth'

d)

'ytho'

18.

What is the output of the following code? s = 'abcabc' print(s.strip('a'))

a)

bc

b)

abcabc

c)

abc

d)

bcabc

19.

Which collection type maintains insertion order as of Python 3.7+?

a)

Dictionary

b)

List

c)

Tuple

d)

Set

20.

Which of the following is an immutable collection?

a)

Dictionary

b)

Set

c)

Tuple

d)

List

21.

What is the data structure used in breadth-first search (BFS)?

a)

Set

b)

Queue

c)

List

d)

Stack

22.

What does `set([1,2,2,3])` return?

a)

(1,2,3)

b)

{1,2,2,3}

c)

[1,2,3]

d)

{1,2,3}

23.

What will be the output of the following code ?

a)

2 2

b)

3 2

c)

2 3

d)

3 3

24.

s = "automation"

vowels = "aeiou"

result = []

for i in range(len(s)):

if s[i] in vowels:

if i % 2 == 0:

result.append(s[i].upper())

else:

result.append(s[i])

print("".join(result))

a)

uoaiio

b)

uoAiio

c)

Auoaio

d)

AuoAio