Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 25

Worksheet time: 25mins

Name
Class
Date
1.

Which of the following best describes Python?

a)

Python is a low-level, compiled programming language.

b)

Python is an interpreted, high-level programming language.

c)

Python is only used for web development.

d)

Python cannot be used for automation.

2.

Which of the following are examples of floating-point literals in Python? (Select all that apply)

a)

3.14

b)

0.0

c)

3

d)

-2.5

3.

What is the purpose of the `input()` function?

a)

To display output to the user.

b)

To perform calculations.

c)

To receive input from the user.

d)

To define a new variable.

4.

What is the result of `5 + 3 * 2` in Python?

a)

16

b)

11

c)

13

d)

8

5.

What is the output of `5 >> 1`?

a)

10

b)

2

c)

0

d)

3

6.

Which of the following are valid uses of logical operators? (Select all that apply)

a)

`True and False`

b)

`not True`

c)

`True or False`

d)

`True xor False`

7.

What will `3 != 4` return?

a)

True

b)

False

c)

Error

d)

None

8.

Complete the expression to convert the string `'123'` into an integer:

(a)  

9.

What is the output of `print("A", "B", sep="-")`?

a)

A B

b)

A-B

c)

AB

d)

A, B

10.

What is the result of `len(str(100))`?

a)

100

b)

1

c)

3

d)

0

11.

Which keyword is used to execute a block of code multiple times?

a)

if

b)

loop

c)

for

d)

repeat

12.

What is the purpose of `continue` in a loop?

a)

To skip the rest of the loop and continue to the next iteration.

b)

To exit the loop.

c)

To pause the loop.

d)

To restart the loop.

13.

Which of these loop structures are valid in Python? (Select all that apply)

a)

`for i in range(5):`

b)

`while i < 10:`

c)

`do while i < 10:`

d)

`foreach i in list:`

14.

What will this code print?

for i in range(3):

if i == 1:

break

print(i)

a)

0

b)

1 2

c)

0 1 2

d)

0 1

15.

What is a nested loop?

a)

A loop with many conditions

b)

A loop that runs after another loop finishes

c)

A loop inside another loop

d)

A loop that repeats forever

16.

Which method can be used to add an item to a list?

a)

insertFirst()

b)

push()

c)

append()

d)

add()

17.

What is the output of this code?

my_tuple = ("a", "b", "c")

print(my_tuple[2])

a)

a

b)

b

c)

c

d)

Error

18.

Which of the following is NOT allowed for a tuple?

a)

Indexing

b)

Slicing

c)

Modifying elements

d)

Iterating

19.

Which of the following are dictionary methods? (Select all that apply)

a)

keys()

b)

items()

c)

values()

d)

length()

20.

What does this code do?

my_dict = {"x": 1, "y": 2}

print("z" in my_dict)

a)

Prints the value of key "z"

b)

Returns True

c)

Returns False

d)

Throws an error

21.

What is the purpose of the `return` statement in a function?

a)

It ends the function and returns a value.

b)

It pauses the function.

c)

It exits the loop.

d)

It prints the result.

22.

What is `None` in Python?

a)

A keyword that means zero

b)

A keyword that means empty string

c)

A special constant representing no value

d)

A syntax error

23.

Which of the following are valid ways to pass arguments to a function? (Select all that apply)

a)

Positional

b)

Keyword

c)

Mixed

d)

Static

24.

Which of the following is true about recursion?

a)

A function cannot call itself

b)

It is the same as iteration

c)

A recursive function must have a base case

d)

Recursive functions are not allowed in Python

25.

What will the following code output?

try:

print(1 / 0)

except:

print("Division by zero")

a)

1

b)

0

c)

Division by zero

d)

Error