wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.

Which of the following is the correct way to print "Hello World" in Python?

a)

print("Hello World")

b)

print("Hello World")

c)

System.out.print("Hello World")

d)

console.log("Hello World")

2.

What is the result of the expression 3 * 4 + 2 ** 3 in Python?

a)

20

b)

24

c)

28

d)

14

3.

Which is the correct way to write a single-line comment in Python?

a)

// This is a comment

b)

/* This is a comment */

c)

# This is a comment

d)
4.

Which comparison operator means "not equal to" in Python?

a)

<>

b)

!=

c)

/=

d)

=!

5.

What is the correct syntax for a while loop in Python?

a)

while (x > 0) { }

b)

while x > 0:

c)

do { } while (x > 0)

d)

while: x > 0

6.

How do you properly define a function with two parameters in Python?

a)

define myFunction(x, y):

b)

def myFunction(x, y):

c)

function myFunction(x, y):

d)

myFunction(x, y) define:

7.

Which method converts a string to lowercase in Python?

a)

toLower()

b)

lowercase()

c)

lower()

d)

to_lower()

8.

Which statement is used to exit a loop prematurely in Python?

a)

exit

b)

break

c)

stop

d)

return

9.

What is the correct way to catch an exception in Python?

a)

catch(Exception e) { }

b)

try-catch(Exception e)

c)

try: except Exception:

d)

on Exception:

10.

How do you access the third character in a string str?

a)

str.charAt(2)

b)

str[2]

c)

str(3)

d)

str.get(2)

11.

What is the result of: "Hello".find("l")?

a)

1

b)

2

c)

3

d)

4

12.

Which operator is used for Finding remainder in Python?

a)

/

b)

//

c)

%

d)

\

13.

How do you check if a substring exists in a string?

a)

contains()

b)

exists()

c)

in

d)

has()

14.

What is the output of: len("Python")?

a)

5

b)

6

c)

7

d)

8

15.

What is the result of: 5 % 2?

a)

0

b)

3

c)

1

d)

2

16.

Which logical operator is used to combine multiple conditions in Python?

a)

and

b)

combine

c)

not

d)

or

17.

What is the result of the expression: True or False and False?

a)

Error

b)

None

c)

False

d)

True

18.

What is a nested control structure in programming?

a)

A control structure that contains another control structure within it

b)

A control structure that does not contain any other control structures

c)

A control structure that is used for input/output operations

d)

A control structure that is used only once

19.

Which of the following is an example of a nested control structure?

a)

An if statement inside a for loop

b)

A function definition

c)

A single if statement

d)

A single for loop

20.

What is the primary benefit of using nested control structures?

a)

They make the code run faster

b)

They allow for more complex decision-making processes

c)

They reduce the number of lines of code

d)

They simplify the debugging process