wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Knowledge Check

Total questions: 35

Worksheet time: 35mins

Name
Class
Date
1.

What is the main version of Python currently supported?

a)

Python 1

b)

Python 2

c)

Python 3

2.

What Python function is used to display information on the screen?

a)

len

b)

print

c)

open

3.

What file extension is typically used for Python files?

a)

python

b)

p

c)

py

4.

To show a string on the console, what code would you enter?

a)

print(my message)

b)

println("my message")

c)

print("my message")

5.

If you invoke a program with program.py 1 2, what does the code sys.argv[0] contain?

a)

It contains the program.py, the name of the program

b)

It contains 1, the first command-line argument.

c)

It contains 2, the second command-line argument.

6.

What will happen if you run the statement "1" + 2 ?

a)

It will evaluate to 3.

b)

It will give an error.

c)

It will become "12".

7.

Under what conditions does a test expression that uses the and operator evaluate to True?

a)

A test expression that uses the and operator evaluates to True when both subexpressions are true.

b)

A test expression that uses the and operator evaluates to True when one subexpression is true and the other is false.

c)

A test expression that uses the and operator evaluates to True when both subexpressions are false.

8.

What is the keyword elif short for in Python?

a)

else if

b)

only if

c)

else

9.

What values in a test expression are always interpreted as false?

a)

Any non-zero values

b)

Empty

c)

None and 0

10.

Are strings immutable?

a)

No, because they can be modified.

b)

Yes, because you can't modify them.

c)

No, because you can split them.

11.

What two string methods can you use to check to see whether a word exists in a string?

a)

The .find() and .count() methods.

b)

The .search() and .count()methods.

c)

The .check() and .search() methods.

12.

What is a problem you might run into when you use % for formatting?

a)

When many replacements are needed, it can make a program slower.

b)

The code can be harder to read when many replacements are needed.

c)

It isn't possible to replace more than nine variables.

13.

How can you round down a number when you use f-strings?

a)

Use the .format() method to round down.

b)

Use the round() function inside the string, enclosed in braces ({}).

c)

You can't round a number when you use f-strings. You must round it before you use it in a string.

14.

What function is used to convert a string to an integer?

a)

int

b)

float

c)

input

15.

What function is used to determine an absolute value?

a)

round

b)

floor

c)

abs

16.

What operator is used to determine a modulo?

a)

*

b)

+

c)

%

17.

What symbols are used to start and finish a list?

a)

Parentheses: ()

b)

Brackets: []

c)

Braces: {}

18.

Which statement would return the first value in the list planets?

a)

planets[-1]

b)

planets[1]

c)

planets[0]

19.

Which statement would return the last value in the list planets?

a)

planets[-1]

b)

planets[last]

c)

planets[]

20.

Which statement would sort the list planets?

a)

planets.sort()

b)

planets.in_order()

c)

planets.sorted()

21.

What statement would loop over the sequence collection and assign the variable item?

a)

for each item in collection

b)

for item in collection:

c)

for collection in item:

22.

What is the correct statement to use to unpack variables named left and right from the list turns?

a)

for left, right in turns:

b)

for left and right in turns:

c)

for [left, right] in turns:

23.

What method allows access all key names in a Python dictionary?

a)

keys

b)

values

c)

update

24.

What method can you use to retrieve a value from a dictionary by using the key?

a)

update

b)

get

c)

values

25.

What method can you use to remove a key from a dictionary?

a)

values

b)

[]

c)

pop

26.

Can a function that defines arguments be called without arguments?

a)

No, because defined arguments are required.

b)

Yes, because they're optional.

c)

Yes, as long as there's a return value.

27.

Can a function with only keyword arguments be called without any arguments?

a)

Can a function with only keyword arguments be called without any arguments?

b)

No, because you must pass values so that the function can work.

c)

No, because it needs arguments.

28.

Can a function define arguments and keyword arguments?

a)

No, only arguments or keyword arguments are allowed.

b)

Yes, but only if keyword arguments are defined before arguments.

c)

Yes, but only if arguments are defined after keyword arguments.

29.

What is the minimum number of arguments that a function can accept when you're using variable arguments?

a)

Zero. There's no need to pass any argument at all when you're using variable arguments.

b)

At least one argument is needed because arguments in functions are required.

c)

At least one argument is needed unless it's a keyword argument.

30.

What is the syntax to declare variable arguments and variable keyword arguments?

a)

args, kwargs

b)

a, kw

c)

*args, **kwargs

31.

What are three elements that you might find in a traceback?

a)

A file path, line number, and Python version

b)

A Python version, file path, and function name

c)

A file path, line number, and exception

32.

What two keywords would you use for handling exceptions?

a)

try and except

b)

try and catch

c)

try and unless

33.

Why would using except Exception be unhelpful?

a)

Because it can show a traceback with limited information

b)

Because it can hide what the real problem is

c)

Because you can't raise another exception

34.

When can it be useful to use as err in an except block?

a)

When you want to raise another exception

b)

When you want to reuse or inspect an exception

c)

When you want to avoid having a traceback in the output

35.

What is the right syntax to catch two exceptions in the same except line?

a)

raise (ValueError, TypeError)

b)

except ValueError, TypeError:

c)

except (ValueError, TypeError):