Question 1
Question
Examine the code and determine the value of the variable b when the code completes.
Question 2
Question
Examine the code and determine the output.
Answer
-
{}
-
foo
-
{'obj_name': 'foo'}
-
{'obj_name' = 'foo'}
Question 3
Question
What output will be produced from this snippet of code?
Answer
-
IndexError
-
[]
-
['a', 'b', 'c', 'd', 'e']
Question 4
Question
What is the difference between a tuple and a list?
Question 5
Question
What output will be produced?
Question 6
Question
Is a list a heterogeneous data structure in Python?
Question 7
Question
If a list is mutable in Python, can it hold immutable objects?
Question 8
Question
A tuple is an immutable data structure in Python. Can it hold mutable objects?
Question 9
Question
What is the value of variable d when the code completes?
Answer
-
[1, 'Dublin', 2, 'London', 3, 'Moscow']
-
{1: 'Dublin', 2: 'London', 3: 'Moscow'}
-
An exception is raised
Question 10
Question
Is the code performing legal operations?
Question 11
Question
Do a and b return the same object type?
Question 12
Question
Determine the value of the variable b when the code completes?
Answer
-
[10,20,30]
-
20
-
[10, 20, 50]
Question 13
Question
What is the output from this code?
Question 14
Question
What is the output of the code?
Question 15
Question
What is the output of the code?
Answer
-
'age under 30'
-
'age equals 25'
-
None of the above
Question 16
Question
Determine the output of the code?
Answer
-
{house:1215}, 'apt
-
An exception is raised
-
'apt', {house:1215}
Question 17
Question
What is the output?
Answer
-
0 2
-
john sarah
-
An exception is raised
Question 18
Question
Which line of code is correct to detect if a variable is a function?
Answer
-
hasattr(obj, '__call__')
-
isinstance(x, function)
-
type(x) == 'function'
Question 19
Question 20
Question
What is the value of the variable name when the code completes?
Question 21
Question
What is the "__init__.py" file for in a Python source directory?
Question 22
Question
Is new_list a shallow or deep copy of old_list?
Question 23
Question
Determine what the output will be?
Answer
-
['j','o','h','n']
-
'John'
-
'mylist'
Question 24
Question
What is the output of the code?
Question 25
Question
Determine the value of a after the method is called twice.
Question 26
Question
Determine the output of the code?
Question 27
Question
What is the output of the code?
Question 28
Question
What is the output of the code?
Question 29
Question
I want to read from a file on the path 'C:\newfile\textfile.txt'. What is the correct way to open the file?
Answer
-
myfile = open('C:\newfile\textfile.txt', 'r')
-
myfile = open(r'C:\newfile\textfile.txt', 'r')
Question 30
Question
Review the code. Does the variable a have a type? If so, what is the type of a?
Answer
-
Variable a does not have a type
-
Variable a is of type List
-
Variable a is of type String
Question 31
Question
Is that code legal?
Question 32
Question
Determine the result?
Question 33
Question
Is the code legal or illegal?
Question 34
Question
What is the result of the code?
Question 35
Question
What output does the code produce?
Answer
-
['jack', 'peter', 'sarah']
-
['sarah']
-
[ 'sarah', 'peter', jack']
Question 36
Question
Analyse the code and determine the result
Question 37
Question
What is the output?
Answer
-
[10]
-
raises an exception
-
[[10]]
Question 38
Question
What object types do variables a and b point to?