1.
What does the following code do?
def a(b, c, d): pass
A. 
Defines a list and initializes it
B. 
Defines a function, which does nothing
C. 
Defines a function, which passes its parameters through
D. 
2.
All keywords in Python are in:
A. 
B. 
C. 
D. 
3.
What gets printed?
x = 4.5
y = 2
print x//y
A. 
B. 
C. 
D. 
E. 
4.
What is the output of the below program?
a = [1,2,3,None,(),[],]
print len(a)
A. 
B. 
C. 
D. 
E. 
5.
What gets printed?
x = True
y = False
z = False
if x or y and z:
print "yes"
else:
print "no"
6.
If PYTHONPATH is set in the environment, which directories are searched for modules?
A) PYTHONPATH directory
B) current directory
C) home directory
D) installation dependent default path
A. 
B. 
C. 
D. 
E. 
7.
In python 2.6 or earlier, the code will print error type 1 if access secure system raises an exception of either AccessError type or SecurityError type
try:
accessSecureSystem()
except AccessError, SecurityError:
print "error type 1"
continueWork()
8.
What gets printed?
print r"\nwoow"
A. 
New line then the string: woow
B. 
The text exactly like this: r"\nwoow"
C. 
The text like exactly like this: \nwoow
D. 
The letter r and then newline then the text: woow
E. 
The letter r then the text like this: nwoow
9.
What gets printed?
print "\x48\x49!"
A. 
B. 
C. 
D. 
E. 
10.
What gets printed?
class parent:
def __init__(self, param):
self.v1 = param
class child(parent):
def __init__(self, param):
self.v2 = param
obj = child(11)
print "%d %d" % (obj.v1, obj.v2)
A. 
B. 
C. 
Error is generated by program
D. 
E. 
11.
What sequence of numbers is printed?
values = [2, 3, 2, 4]
def my_transformation(num):
return num ** 2
for i in map(my_transformation, values):
print i
A. 
B. 
C. 
D. 
E. 
12.
What does the code below do?
sys.path.append('/root/mods')
A. 
Changes the location that the python executable is run from
B. 
Changes the location where sub-processes are searched for after they are launched
C. 
Removes all directories for mods
D. 
Adds a new directory to seach for python modules that are imported
E. 
Changes the current working directory
13.
Assuming the filename for the code below is /usr/lib/python/person.py
and the program is run as:
python /usr/lib/python/person.py
What gets printed?
class Person:
def __init__(self):
pass
def getAge(self):
print __name__
p = Person()
p.getAge()
A. 
B. 
C. 
D. 
E. 
14.
Which of the following data structures can be used with the "in" operator to check if an item is in the data structure?
A. 
B. 
C. 
D. 
E. 
15.
What gets printed?
class A:
def __init__(self, a, b, c):
self.x = a + b + c
a = A(1,2,3)
b = getattr(a, 'x')
setattr(a, 'x', b+1)
print a.x
A. 
B. 
C. 
D. 
E. 
16.
Which of the following statements is NOT true about Python?
A. 
Python's syntax is much like PHP
B. 
Python can be used for web development
C. 
Python can run on any type of platform
D. 
Python can be used to generate dynamic web pages
17.
If you have a variable "example", how do you check to see what type of variable you are working with?
A. 
B. 
C. 
D. 
18.
If you had a statement like, "f = open("test.txt","w")", what would happen to the file as soon as that statement is executed?
A. 
Nothing, unless the code following it writes to the file
B. 
The file's contents will be erased
C. 
D. 
Python will save the file's contents and append whatever the code following says to write.
19.
Given a function that does not return any value, What value is thrown by it by default when executed in a shell.
A. 
B. 
C. 
D. 
20.
Which of the following will run without errors?
A. 
B. 
C. 
D. 
21.
Which of the following results in a SyntaxError?
A. 
'"Once upon a time…", she said.'
B. 
C. 
D. 
22.
Is the following code valid?
try:
# Do something
except:
# Do something
finally:
# Do something
A. 
no, there is no such thing as finally
B. 
no, finally cannot be used with except
C. 
no, finally must come before except
D. 
23.
How many except statements can a try-except block have?
A. 
B. 
C. 
D. 
24.
Can one block of except statements handle multiple exception?
A. 
Yes, like except TypeError, SyntaxError [,…]
B. 
yes, like except [TypeError, SyntaxError
C. 
D. 
25.
Which of the following will print True?a = foo(2)
b = foo(3)
print(a < b)
A. 
Class foo:
def __init__(self, x):
self.x = x
def __lt__(self, other):
if self.x < other.x:
return False
else:
return True
B. 
Class foo:
def __init__(self, x):
self.x = x
def __less__(self, other):
if self.x > other.x:
return False
else:
return True
C. 
Class foo:
def __init__(self, x):
self.x = x
def __lt__(self, other):
if self.x < other.x:
return True
else:
return False
D. 
Class foo:
def __init__(self, x):
self.x = x
def __less__(self, other):
if self.x < other.x:
return False
else:
return True