wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 40

Worksheet time: 20mins

Name
Class
Date
1.

What is the output of print(type(10))?

a)

<class 'float'>

b)

 <class 'int'>

c)

<class 'str'>

d)

<class 'bool'>

2.

What is the correct extension of a Python file?

a)

.py

b)

.python

c)

.pyt

d)

.pt

3.

What is the keyword used to define a function in Python?

a)

func

b)

def

c)

define

d)

function

4.

What will be the output of print(2 ** 3)?

a)

5

b)

6

c)

8

d)

9

5.

How do you take input from a user in Python?

a)

get()

b)

scan()

c)

input()

d)

read()

6.

What is the output of print(10/3)?

a)

3.0

b)

3.33

c)

3

d)

Error

7.

What is the result of print(10 // 3)?

a)

3.33

b)

3.0

c)

3

d)

Error

8.

Which of the following is immutable?

a)

list

b)

tuple

c)

set

d)

dictionary

9.

What is the correct way to declare a list?

a)

list = {1, 2, 3}

b)

list = (1, 2, 3)

c)

list = [1, 2, 3]

d)

list = <1, 2, 3>

10.

What does append() do in a list?

a)

Adds an element at a specific index

b)

Adds an element at the end

c)

Removes the last element

d)

Sorts the list

11.

Which of the following is a valid variable name in Python?

a)

1name

b)

_name

c)

name@

d)

class

12.

How do you create an empty set in Python?

a)

s = {}

b)

s = []

c)

s = ()

d)

s = set()

13.

What will be the output of print("Hello"[1])?

a)

H

b)

e

c)

l

d)

o

14.

What does range(5) return?

a)

[0, 1, 2, 3, 4]

b)

(0, 1, 2, 3, 4)

c)

{0, 1, 2, 3, 4}

d)

None

15.

What will bool([]) return?

a)

True

b)

False

c)

None

d)

Error

16.

How do you check the length of a list l?

a)

length(l)

b)

l.size()

c)

len(l)

d)

count(l)

17.

Which statement is used to stop a loop?

a)

exit

b)

break

c)

stop

d)

return

18.

Which loop executes at least once?

a)

for

b)

while

c)

do-while

d)

None

19.

What is the output of print(type(None))?

a)

b)

c)

d)

Error

20.

How do you remove an item from a list by value?

a)

pop()

b)

del

c)

remove()

d)

discard()

21.

How do you create a dictionary?

a)

{}

b)

[]

c)

()

d)

<>

22.

What is the default return type of input()?

a)

int

b)

float

c)

str

d)

bool

23.

What is the keyword to define a class?

a)

define

b)

class

c)

object

d)

new

24.

What is used to handle exceptions?

a)

try-except

b)

catch-throw

c)

if-else

d)

error handling

25.

How do you access a value in a dictionary?

a)

dict.key()

b)

dict[key]

c)

dict.key

d)

dict.getvalue(key)

26.

What will be the output of the following Python code? x = 5 y = 2 print(x ** y)

a)

10

b)

25

c)

7

d)

32

27.

What will be the output of this code? def fun(): return 10 print(fun())

a)

10

b)

None

c)

Error

d)

0

28.

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

a)

[1, 2, 3]

b)

[1, 2, 3, 4]

c)

Error

d)

[4]

29.

What will be the output of this code? for i in range(3): print(i, end=" ")

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

None

30.

What does the following code output? def add(a, b=5): return a + b print(add(2))

a)

5

b)

7

c)

2

d)

None

31.

What is the output of this code? x = "Hello" print(x[::-1])

a)

Hello

b)

olleH

c)

Error

d)

None

32.

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

a)

2

b)

3

c)

1

d)

Error

33.

What is the output of this Python program? def multiply(x, y): return x * y print(multiply(3, 4))

a)

12

b)

7

c)

3 * 4

d)

None

34.

What will be the output of this program? x = "Python" print(x[2:])

a)

Py

b)

thon

c)

Python

d)

Error

35.

What is the output of the following Python script? for i in range(1, 4): for j in range(1, 4): print(i * j, end=" ") print()

a)

1 2 3 2 4 6 3 6 9

b)

1 2 3 4 5 6 7 8 9

c)

1 4 9 1 4 9 1 4 9

d)

None

36.

What will be the output of print(bool([]))?

a)

True

b)

False

c)

Error

d)

None

37.

What does list.append(4) do?

a)

Adds 4 at the beginning

b)

Adds 4 at the end

c)

Removes 4

d)

Does nothing

38.

What is the output of print(type({}))?

a)

b)

c)

d)

39.

What will print(5 % 2) return?

a)

0

b)

1

c)

2

d)

5

40.

What does ord('A') return?

a)

A

b)

65

c)

Error

d)

None