wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Quiz

Total questions: 13

Worksheet time: 7mins

Name
Class
Date
1.

What method would you use to remove whitespace from the right side of a string?

a)

remove()

b)

lstrip()

c)

rstrip()

d)

strip()

2.

How would you remove the prefix "www." from the string "www.example.com"?

a)

deleteprefix('www.')

b)

remove('www.')

c)

stripprefix('www.')

d)

removeprefix('www.')

3.

What does the expression 7 // 2 evaluate to?

a)

1

b)

3

c)

3.5

d)

4

4.

What does the expression 7 % 2 evaluate to?

a)

1

b)

3

c)

3.5

d)

4

5.

Which operation would you use to raise 2 to the power of 3?

a)

2 * 3

b)

2 ^ 3

c)

2 ** 3

6.

What is the result of 5 / 2 in Python?

a)

2

b)

2.5

c)

2.0

d)

3

7.

How can you assign values 10, 20, and 30 to variables x, y, and z in one line?

a)

assign x=10, y=20, z=30

b)

x; y; z = 10; 20; 30

c)

x, y, z = 10, 20, 30

d)

x = 10, y = 20, z = 30

8.

How do Python programmers typically indicate that a variable should be treated as a constant?

a)

Adding an exclamation mark at the end

b)

Putting it in parentheses

c)

Naming it with all capital letters

d)

Using the const keyword

9.

What does the input() function return?

a)

It depends on what the user enters

b)

A string

c)

A float

d)

An integer

10.

What is the result of 2 + 3 * 4?

a)

10

b)

14

c)

20

d)

24

11.

The strip() method removes whitespace from both ends of a string.

a)

True

b)

False

12.

True or False: The expression 5 / 2 in Python results in 2.

a)

True

b)

False

13.

True or False: When using input(), you should always convert numerical input to the appropriate type before performing calculations.

a)

True

b)

False