NEW
Font size
WorksheetsPython Knowledge Check
Total questions: 35
Worksheet time: 35mins
What is the main version of Python currently supported?
Python 1
Python 2
Python 3
What Python function is used to display information on the screen?
len
open
What file extension is typically used for Python files?
python
p
py
To show a string on the console, what code would you enter?
print(my message)
println("my message")
print("my message")
If you invoke a program with program.py 1 2, what does the code sys.argv[0] contain?
It contains the program.py, the name of the program
It contains 1, the first command-line argument.
It contains 2, the second command-line argument.
What will happen if you run the statement "1" + 2 ?
It will evaluate to 3.
It will give an error.
It will become "12".
Under what conditions does a test expression that uses the and operator evaluate to True?
A test expression that uses the and operator evaluates to True when both subexpressions are true.
A test expression that uses the and operator evaluates to True when one subexpression is true and the other is false.
A test expression that uses the and operator evaluates to True when both subexpressions are false.
What is the keyword elif short for in Python?
else if
only if
else
What values in a test expression are always interpreted as false?
Any non-zero values
Empty
None and 0
Are strings immutable?
No, because they can be modified.
Yes, because you can't modify them.
No, because you can split them.
What two string methods can you use to check to see whether a word exists in a string?
The .find() and .count() methods.
The .search() and .count()methods.
The .check() and .search() methods.
What is a problem you might run into when you use % for formatting?
When many replacements are needed, it can make a program slower.
The code can be harder to read when many replacements are needed.
It isn't possible to replace more than nine variables.
How can you round down a number when you use f-strings?
Use the .format() method to round down.
Use the round() function inside the string, enclosed in braces ({}).
You can't round a number when you use f-strings. You must round it before you use it in a string.
What function is used to convert a string to an integer?
int
float
input
What function is used to determine an absolute value?
round
floor
abs
What operator is used to determine a modulo?
*
+
%
What symbols are used to start and finish a list?
Parentheses: ()
Brackets: []
Braces: {}
Which statement would return the first value in the list planets?
planets[-1]
planets[1]
planets[0]
Which statement would return the last value in the list planets?
planets[-1]
planets[last]
planets[]
Which statement would sort the list planets?
What statement would loop over the sequence collection and assign the variable item?
for each item in collection
for item in collection:
for collection in item:
What is the correct statement to use to unpack variables named left and right from the list turns?
for left, right in turns:
for left and right in turns:
for [left, right] in turns:
What method allows access all key names in a Python dictionary?
keys
values
update
What method can you use to retrieve a value from a dictionary by using the key?
update
get
values
What method can you use to remove a key from a dictionary?
values
[]
pop
Can a function that defines arguments be called without arguments?
No, because defined arguments are required.
Yes, because they're optional.
Yes, as long as there's a return value.
Can a function with only keyword arguments be called without any arguments?
Can a function with only keyword arguments be called without any arguments?
No, because you must pass values so that the function can work.
No, because it needs arguments.
Can a function define arguments and keyword arguments?
No, only arguments or keyword arguments are allowed.
Yes, but only if keyword arguments are defined before arguments.
Yes, but only if arguments are defined after keyword arguments.
What is the minimum number of arguments that a function can accept when you're using variable arguments?
Zero. There's no need to pass any argument at all when you're using variable arguments.
At least one argument is needed because arguments in functions are required.
At least one argument is needed unless it's a keyword argument.
What is the syntax to declare variable arguments and variable keyword arguments?
args, kwargs
a, kw
*args, **kwargs
What are three elements that you might find in a traceback?
A file path, line number, and Python version
A Python version, file path, and function name
A file path, line number, and exception
What two keywords would you use for handling exceptions?
try and except
try and catch
try and unless
Why would using except Exception be unhelpful?
Because it can show a traceback with limited information
Because it can hide what the real problem is
Because you can't raise another exception
When can it be useful to use as err in an except block?
When you want to raise another exception
When you want to reuse or inspect an exception
When you want to avoid having a traceback in the output
What is the right syntax to catch two exceptions in the same except line?
raise (ValueError, TypeError)
except ValueError, TypeError:
except (ValueError, TypeError):
