Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Theory

Total questions: 17

Worksheet time: 17mins

Name
Class
Date
1.

What is a valid shebang line?

a)

!/usr/local/env python3

b)

#/usr/local/env python3

c)

##/usr/local/bin/python3

d)

#!/usr/local/bin/python3

2.

Which line is an expression but NOT a statement?

a)

break

b)

x=x+1

c)

print('hello')

d)

True

3.

In Python, a statement is _____.

a)

a line of code

b)

a function call

c)

a combination of literals, identifiers, and operators

d)

an operation

4.

What will this code produce?

a)

It will print a is 6.

b)

It will print a is 5.

c)

It will fail on a logical error.

d)

It will print nothing.

5.

What is the issue with this mock code?

a)

The else block must come before the elif block.

b)

An elif block cannot be followed by an else block.

c)

The do C block may run before the do B block.

d)

The do C block will never be executed.

6.

Which loop type will always complete at least one iteration?

a)

none of these answers

b)

the until loop

c)

the while loop

d)

the for loop

7.

Which statement is true regarding this function definition?

a)

The function will not return anything.

b)

The function will return a value of none.

c)

The function will return the value of 5.

d)

A syntax error will be reported.

8.

What will this Python script print?

a)

A

B

C

b)

B

C

c)

A

C

d)

C

A

9.

What is the purpose of Hello World?

a)

to activate your Python account

b)

to introduce yourself to the Python community

c)

to validate your development environment

d)

to communicate with other Python users

10.

What is the equivalent f-string notation of this code?

a)

print('x is {f(x)}')

b)

print('x is f{x}')

c)

print('x is {x}'.f())

d)

print(f'x is {x}')

11.

Why do blocks in Python need to be indented at the same level?

a)

so they are considered grammatically correct

b)

so they can print in readable text

c)

so they can be edited in the same font

d)

so they are considered part of the same block

12.

What will the following code print?

a)

x > y: y is 42 and X is 73

b)

x = 42: y is 73 and x is 42

c)

x < y: x is 42 and y is 73`

d)

y = 73; y is 73 and x is 42

13.

What will the following code print?

a)

one

two

three

four

five

six

b)

one

two

three

four

five

c)

zero

one

two

three

four

five

d)

`` zero one ```

14.

What will the following code print?

a)

0

b)

1

c)

error

d)

n

15.

In the following code, what is the object?

a)

quack

b)

Donald walk like a duck

c)

Donald

d)

walk

16.

Will this code work? If not, how how should you fix it?

a)

This code will work correctly, printing the height as specified.

b)

This code will fail. To fix the code, replace format(height) in line 4 with format(self.height).

c)

This code will fail. To fix the code, change line 2 to height=self.height.

d)

This code will fail. To fix the code, switch the order of lines 5 and 6.

17.

LANGUAGE OVERVIEW

What will this Python code print

a)

A,B,C

b)

A

B

C

c)

A,B

C

d)

C

A,B