wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which of the following data types is mutable in Python?

a)

String

b)

Tuple

c)

List

d)

Frozenset

2.

What will be the output of the following code snippet? def func(x=[]): x.append(1) return x print(func()) print(func())

a)

[1] [1]

b)

[1] [1, 1]

c)

[1, 1] [1, 1]

d)

Syntax Error

3.

What will be the output of the following code? x = [1, 2, 3, 4] y = x y.append(5) print(x)

a)

[1, 2, 3, 4]

b)

[1, 2, 3, 4, 5]

c)

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

d)

[5]

4.

What will be the output of the following code snippet? print("Hello, World!"[::-1])

a)

"dlroW ,olleH"

b)

"Hello, World!"

c)

Error

d)

None

5.

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

a)

3

b)

4

c)

5

d)

Error

6.

Which of the following statements is incorrect about Python dictionaries?

a)

Keys must be unique.

b)

Values must be unique.

c)

Keys must be immutable.

d)

Values can be of any data type.

7.

What does the lambda keyword in Python define?

a)

A class

b)

A function

c)

A module

d)

A loop

8.

Which of the following methods will convert a list into a tuple?

a)

list()

b)

dict()

c)

tuple()

d)

set()

9.

What will be the output of the following code snippet? x = [1, 2, 3] y = x * 2 print(y)

a)

[1, 2, 3]

b)

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

c)

Error

d)

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

10.

What does the following Python expression evaluate to? bool([]) and bool("")

a)

True

b)

False

c)

Syntax Error

d)

Type Error

11.

What is the output of the following code? a = (1, 2) a[0] = 5

a)

(5, 2)

b)

(1, 2)

c)

Error

d)

(1, 5)

12.

Which of the following statements about the continue statement is true?

a)

It terminates the loop.

b)

It skips the rest of the code inside the loop for the current iteration.

c)

It moves to the previous iteration.

d)

It raises an error if used inside a loop.

13.

What will be the output of the following code snippet? def f(x, y=[]): y.append(x) return y print(f(1)) print(f(2))

a)

[1] [2]

b)

[1] [1, 2]

c)

[1, 2] [1, 2]

d)

Error

14.

Which of the following operators cannot be overloaded in Python?

a)

+

b)

//

c)

==

d)

and

15.

What is the result of the following code? a = {1, 2, 3} b = {3, 4, 5} print(a & b)

a)

{1, 2, 3, 4, 5}

b)

{3}

c)

{1, 2}

d)

{}