0 O 1
O O
O 1 None 0
Answer
Correct Answer:
O 1 None 0
Note: This Question is unanswered, help us to find answer for this one
Check Answer
118. What will be the correct output of the following Python language code?
from datetime import date
class Sn:
def __init_(self. n. a):
self.n = n
selfia = a
@classmethod
def fBY(cl, n, y):
return cl(n. 2018 - y+1)
@staticmethod
def sA(a):
return a > 28
sn1 = Sn(
42 False
45 True
45 False
46 True
44 False
Note: This Question is unanswered, help us to find answer for this one
Check Answer
119. What will be the correct output of the following Python code?
n1 = 90
n2 =18
x=n1-n2
X: x >> 3
print(x)
8
9
12
Note: This Question is unanswered, help us to find answer for this one
Check Answer
120.
What will be the output of the Python code that is given in the image?
Two Python5
Four Python5
Three Python5
Answer
Correct Answer:
Two Python5
Note: This Question is unanswered, help us to find answer for this one
Check Answer
121. What will be the correct output of the following Python code?
from functools import ‘
def add(a, b, c):
return 1000'a +10‘b + c
add_part = partia|(add, c=2, b=1)
print(add_part(3))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
122.
ln Python 3.4.2, what will be the output of the code given in the image?
0 gm spr 918.0 Python is a powerful programming language.
0 spr gm p23.0 Python is a powerful programming language.
0 gm spr p22.0 Python is a powerful programming language.
0 spr gm g21.0 Python is a powerful programming language.
Answer
Correct Answer:
0 spr gm g21.0 Python is a powerful programming language.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
123. The file formats created by the ‘dbm.ndbm’ module and the 'dbm.gnu' module are always compatible
with each other.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
124. Which of the following options will be the output of the Python code given in the image?
gnsgirstr cjavhi icrti,neee as .. t64.5
gnigirser cjauvihi eicri,een as .. 76.0
gnigirster cjaevhi eicrtineee as .. t66.0
gngirster cjavhi eicrti,eeen as .. t108.5
gngirster cjavhi eicrti,eeen as .. t74.5
Answer
Correct Answer:
gngirster cjavhi eicrti,eeen as .. t108.5
Note: This Question is unanswered, help us to find answer for this one
Check Answer
125. Find the output of the following Python code and choose the correct answer from the given options.
try :
a = 3
if a < 4 :
b = a/(a-3)
print (b)
except(ZeroDivisionError, NameError):
print ("1")
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
126. Choose the correct output of the following function in Python 3.4.2 shell? float(
0
1
Infinity
-inf
ValueError:could not convert string to float
Note: This Question is unanswered, help us to find answer for this one
Check Answer
127. In Python 3.4.2, how many exception statements can you write in a "try" block?
only one exception
two exceptions
three exceptions
multiple exceptions
Answer
Correct Answer:
multiple exceptions
Note: This Question is unanswered, help us to find answer for this one
Check Answer
128. In relation to the socket low-level networking interface in Python, which of the following exceptions is
raised for the address-related errors?
Answer
Correct Answer:
socket.gaierror
Note: This Question is unanswered, help us to find answer for this one
Check Answer
130. What will be the correct output of the following Python code?
try:
a=10
print (a-9)
raise NameError("0")
except NameError as e:
print ("1")
print (e)
finally:
print ("0")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
131. What will be the correct output of the following Python code?
def recur_factorial(n):
if n == 1:
return 1
else:
return n'recur_factorial(n-1)
num = 4
if num < O:
print("1") elif num = O: print("0") else: p=41+(recur_factorial(num)) p=P>>2 printlp)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
132. What will be the correct output of the following Python code?
def hello():
print("0")
return("1")
def hello2():
print("0")
hello() * 2
hello2()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
133. What will be the correct output of the following Python code?
def p_ft(x):
for i in range(1, x + 1):
if x % i == 0:
d=6/2+i
print(d+9)
n = 42
p_ft(n)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
134. What will be the correct output of the following Python code?
lst = [3, 1, 2, 5, 4, 3, 8]
del lst[2 : 5]
print (end="")
for i in range(0, len(lst)):
print(lst[i]+1, end=" ")
print("\r")
lst.pop(2)
print (end="")
for i in range(0, len(lst)):
print(lst[i]+2, end=" ")
Answer
Correct Answer:
4 2 4 9
5 3 10
Note: This Question is unanswered, help us to find answer for this one
Check Answer
135. Analyse the given Python code and answer the question that follows.
def att_d(fun):
fun.data = 3
return fun
@att_d
def xyz (x. y):
return x + y‘2
print(xyz(2, 23))
print(xyz.data)
What will be the correct output of the above Python code?
Note: This Question is unanswered, help us to find answer for this one
Check Answer
136. Find the output of the following Python code and choose the correct answer from the given options.
m = 7
tor = 1
if m < 0:
print("0")
elif m == 0:
print("1")
else:
for i in range(1,m + 1):
tor = tor*i
print(tor)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
137. What will be the correct output of the following Python code?
lstx = range(1, 11)
print(lstx)
lst1_x5 = lstx[1 : 5]
print (lst1_x5)
lst5_x = lstx[5 : 8]
print (lst5_x)
lst1_y = lstx[1 : ]
print (lst1_y)
lst_x5 = lstx[: 5]
print (lst_x5)
lst1_8_2 = lstx[1 : 8 : 2]
print (lst1_8_2)
lst_rev = lstx[ : : -1]
print (lst_rev)
lst_rev_9_5_2 = lstx[9 : 4 : -2]
print (lst_rev_9_5_2)
range(1, 10)
range(2, 4)
range(6, 8)
range(2, 10)
range(1, 5)
range(2, 7, 3)
range(11, 0, -1)
range(10, 5, -2)
range(1, 11)
range(2, 5)
range(6, 8)
range(2, 11)
range(1, 5)
range(2, 9, 2)
range(10, 0, -1)
range(10, 5, -2)
range(1, 11)
range(2, 6)
range(6, 9)
range(2, 11)
range(1, 6)
range(2, 9, 2)
range(10, 0, -1)
range(10, 5, -2)
No output will be displayed.
Answer
Correct Answer:
range(1, 11)
range(2, 6)
range(6, 9)
range(2, 11)
range(1, 6)
range(2, 9, 2)
range(10, 0, -1)
range(10, 5, -2)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
138. What will be the correct output of the following Python code?
def abc():
y = 2018
if (y % 4) == 0:
if (y % 100) == 0:
if (y % 400) == 0:
print("0")
else:
print("1")
else:
print("0")
else:
print("1")
abc()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
139. This question is based on the graphic shown below.
Choose the correct output of the given Python 3.4 code.
Hello ajus
I am good
Hello angee
How are you?
val : 30
Hello ajus
I am good
Hello angee
How are you?
val : 25
Hello ajus
I am good
How are you?
val :30
Hello ajus
I am good
How are you?
val : 25
Answer
Correct Answer:
Hello ajus
I am good
How are you?
val :30
Note: This Question is unanswered, help us to find answer for this one
Check Answer
140. Select the correct output of the following Python code from the given options.
class St:
stm = 'Y' stm = 'X' def __init__(self, r): self.r = r def setdd(self, dd): self.dd = dd def getdd(self): return self.dd a = St(101) a.setdd("Y, UP") a.setdd("X") print(a.getdd()) ">
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
141. Analyse the following Python code and choose the correct answer from the given options.
class D:
def __init__(self, l, c):
self.l = l
self.c = c
def b(self):
b = "1" * 2
return b
if __name__ == "__main__":
d = D(4, "0")
b = d.b()
print(b)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
142. What will be the correct output of the following Python code?
def abc(n):
if n <= 1:
return n
else:
return(abc(n-1) + abc(n-2))
print("1")
nterms = 13
if nterms <= 0:
print("0")
else:
for i in range(nterms):
x=abc(i)
print(x+11)
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
143. What will be the correct output of the following Python code?
class X(object):
def __init__(self,a):
self.num = a
def dbup(self):
self.num *= 2
class Y(X):
def __init__(self,a):
X.__init__(self, a)
def tpup(self):
self.num*= 3
obj = Y(4)
print(obj.num*2/1)
obj.dbup()
print(obj.num*3/2)
obj.tpup()
print(obj.num/2*3)
Answer
Correct Answer:
8.0
12.0
36.0
Note: This Question is unanswered, help us to find answer for this one
Check Answer
144. What will be the output of the following function in Python 3.4 shell? float(
0.01
0.003
0.001
0.03
Note: This Question is unanswered, help us to find answer for this one
Check Answer
145. Which of the given shell expressions in Python 3.4.2 will give an error?
>>>'hi';
>>>'hello';
>>>Good morning;
>>>''Good evening'';
Answer
Correct Answer:
>>>Good morning;
Note: This Question is unanswered, help us to find answer for this one
Check Answer
146. What will be the correct output of the following Python language code?
import bisect
ct = [1, 3, 4, 4, 4, 6, 7]
c2 = [1, 3, 4. 4, 4. 6. 7]
c3 = [1. 3, 4. 4. 4. 6, 7]
blsectlnsort(c1. 5)
bisectinsort_left(c2, 5)
bisectinsort_right(c3, 5. 0. 4)
for l in range(O, 7):
print(c3[i], end=' ')
Answer
Correct Answer:
1 3 4 4 5 4 6
Note: This Question is unanswered, help us to find answer for this one
Check Answer
147. Which of the following port numbers is used for theTelnet protocol in Python?
20
23
25
70
Note: This Question is unanswered, help us to find answer for this one
Check Answer
148. Which of the following port numbers is used for the FTP protocol in Python?
20
23
25
70
Note: This Question is unanswered, help us to find answer for this one
Check Answer
149. What will be the correct output of the following Python code?
class St:
stm = 'B' stm = 'A' def __init__(self, r): self.r = r a = St(101) b = St(102) print(a.stm) print(b.stm) print(a.r) print(St.stm)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
150. Which of the following options does not contain duplicate elements?
Lists
Sets
Tuples
Strings
Both options a and b
Both options b and c
Both options c and d
Note: This Question is unanswered, help us to find answer for this one
Check Answer
151. Find the output of the following Python code and choose the correct answer from the given options.
def vm(x. y):
If x > y:
greater = x
else:
greater = y
while(True):
if((greater 9-6 x == 0) and (greater % y == 0)):
vm = greater
break
greater += 1
return vm
numi = 64
num2 = 24
print(vm(num1. num2»
Note: This Question is unanswered, help us to find answer for this one
Check Answer
152. What will be the correct output of the following Python code?
def part1(n):
y=1
For i in range(0. n):
For j in range(0. H1):
H1“
Print(y)
n = 5
part1(n)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
153. ln Python language, which of the following information is contained by a thread in the Thread Control
Block (TCB)?
1. Stack pointer
2. Program counter
3. Thread state
4. Parent process Pointer
All options 1. 2. 3. and 4.
Only options 1. 2. and 3.
Answer
Correct Answer:
All options 1. 2. 3. and 4.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
154. Analyse the given Python language code and answer the question that follows.
import collections
fd = collections.defaultdict(lambda : '0')
fdi'a'] = 1
fd['b‘] = 2
print (fd['a']+0)
print (fd['c‘])
print (fd[‘b']+0)
print (fd['d'])
What will be the correct output of the above given code?
Key not found 0.00
0 1+0
0
2+0
0
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
155. Find the output of the following Python code and select the correct answer from the given options.
List = [1. 2. 3. 1. 2. 1. 2. 3. 2. 1]
print(sum(List)+List.count(1)+len(List)+List.index(2)+List.index(2.2))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
156. What will be the correct output of the following Python code?
List = [5, 12, 3, 4, 2, 16, 2, 2, 2, 11]
print(sum(List)+List.count(2)+min(List)+max(List)+List.pop())
del List[0]
del List[6]
print(List.pop(0)+len(List)+List.index(2)+List.index(2,2))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
157. Analyse the following Python code and choose its correct output from the given options.
def comF(x, y):
if x > y:
sm = y
else:
sm = x
for i in range(1, sm+1):
if((x % i == 0) and (y % i == 0)):
cf = i
return cf
num1 = 84
num2 = 64
print(comF(num1, num2))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
158. What will be the correct output of the following Python code?
class Son(object):
def __init__(self, name):
self.name = name
def gN(self):
return self.name
def sE(self):
return False
class Ply(Son):
def sE(self):
return True
mp = Son("1")
print(mp.gN(), mp.sE())
mp = Ply("0")
print(mp.gN(), mp.sE())
Answer
Correct Answer:
False
0 True
True
1 False
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
159. Find the output of the following Python code and choose the correct answer from the given options.
from string import Template
Student = [(‘X',24), ('Y',32), ('2',20)]
t = Template('$rn‘)
for i in Student:
print (t.substitute(n = i[0], m = i[1]‘3-1))
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
160. Which of the following values of the 'timeout’ argument of the acquireo function represents an unbounded wait?
0
1
-1
-2
Note: This Question is unanswered, help us to find answer for this one
Check Answer
161. A lambda function in Python can take __________.
only one argument
only two arguments
only three arguments
any number of arguments
Answer
Correct Answer:
any number of arguments
Note: This Question is unanswered, help us to find answer for this one
Check Answer
162. What will be the correct output of the following Python code?
num1 = 10
num2 = 14
num3 = 12
if (num1 >= num2) and (num1 >= num3):
lg = num1+4
elif (num2 >= num1) and (num2 >= num3):
lg = num2+5
else:
lg = num3+3
print(lg*3)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
163. What will be the correct output of the following Python language code?
from collections import OrderedDict
od = OrderedDict()
od['a'] = 1
od['b'] = 2
od['c'] = 3
od['d'] = 4
for key, value in od.items():
10
10
10
10
01
01
01
a 3
b 4
d 6
c 5
10
10
10
10
01
01
01
01
a 3
b 4
d 5
c 6
10
10
10
10
01
01
01
a 1+2
b 2+2
d 3+2
c 4+2
10
10
10
10
01
01
01
a 1+2
b 2+2
d 4+2
c 3+2
Answer
Correct Answer:
10
10
10
10
01
01
01
a 3
b 4
d 6
c 5
Note: This Question is unanswered, help us to find answer for this one
Check Answer
164. What will be returned by the following function?
threading.enumerate()
It will return the number of currently alive Thread objects.
It will return a list of all Thread objects.
It will return a list of currently alive Thread objects.
It will return a list of Thread objects that are not alive.
Answer
Correct Answer:
It will return a list of currently alive Thread objects.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
165. What will be the correct output of the following Python code?
import sys
rList = ['a', 0, 2]
for bn in rList:
a
2
result 2 is 2.5 0
2
result 2 is 2.5
Code will give a compilation error.
Answer
Correct Answer:
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
166. What will be the correct output of the following Python code?
def part1():
low = 365
up = 372
for num in range(low, up + 1):
order = len(str(num))
s = 0
temp = num
while temp > 0:
digit = temp % 10
s += digit ** order
temp //= 10
if num == s:
print(num)
part1()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
167. Find the output of the following Python code and choose the correct answer from the given options.
def print_f(x):
y=0
for i in range(1, x + 1):
if x % i == 0:
y=y+i+1
print(y)
num = 32
print_f(num)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
168. Find the output of the following Python code and choose the correct answer from the given options.
double = lambda x: x * 2
mt = [1, 5, 4, 6, 8, 11, 3, 12]
ns = list(filter(lambda x: (x%2 == 0) , mt))
print(double(6))
print(ns)
Code will give a compilation error.
Answer
Correct Answer:
12
[4, 6, 8, 12]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
169.
This question is based on the graphic shown below.
Which of the following options will be the correct output of the given Python code?
512
0.125
b'ANGEE'
[(1.0, -8.0), (-15.625, 27.0), (74.08800000000001, 15.625)]
512
0.125
b'ANGEE'
[(1.0, 4.0), (6.25, 9.0), (17.64, 6.25)]
b'ANGEE'
[(1.0, 4.0), (6.25, 9.0), (17.64, 6.25)]
512
0.125
b'ANGEE'
[(1.0, -8.0), (-15.625, 27.0), (74.08800000000001, 15.625)]
512
0.125
Answer
Correct Answer:
512
0.125
b'ANGEE'
[(1.0, 4.0), (6.25, 9.0), (17.64, 6.25)]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
170. What will be the correct output of the following Python code?
print (5/2)
print (-5/2)
print (5.0/2)
print (-5.0/2)
Code will give a compilation error.
Answer
Correct Answer:
2.5
-2.5
2.5
-2.5
Note: This Question is unanswered, help us to find answer for this one
Check Answer
171. Select the correct output of the following Python code from the given options.
import collections
c1 = { 'a' : 1, 'b' : 2 }
c2 = { 'b' : 3, 'c' : 4 }
c3 = { 'f' : 5 }
ch = collections.ChainMap(c1, c2)
#print (ch.maps)
ch1 = ch.new_child(c3)
#print (ch1.maps)
print (ch1['b'])
ch1.maps = reversed(ch1.maps)
print (ch1['b'])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
172. What will be the correct output of the following Python code?
def ps(a,b):
s = a + b
return (s, a)
s, a = ps(0,4)
a=a+4
s1 = 1
i = 1
while i <= a:
s1 = s1 + i
i = i+1
print(s1)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
173. What will be the correct output of the following Python code?
class Son(object):
def __init__(self, n):
self.n = n
def gN(self):
return self.n
def sE(self):
return False
class Ploy(Son):
def __init__(self, n, eid):
super(Ploy, self).__init__(n)
self.empID = eid
def sE(self):
return True
def gID(self):
return self.empID
emp = Ploy("1", "0")
print(emp.gN(), emp.sE(), emp.gID())
Note: This Question is unanswered, help us to find answer for this one
Check Answer
174. What will be the correct output of the following Python code?
class Error(Exception):
“"0..."
pass
class ValueTooSmallError(Error):
"."1uu"
pass
class ValueTooLargeError(Error):
m2"...
pass
number = 10
while True:
try:
i_num =10
if i_num < number:
raise ValueTooSmallError
elif i_num > number:
raise ValueTooLargeError
break
except ValueTooSmallError:
print("1")
printi)
except ValueTooLargeError:
print("1")
printi)
print("0")
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
175. Find the output of the following Python code and choose the correct answer from the given options.
class ErrorInCode(Exception):
def __init__(self, data):
self.data = data
def __str__(self):
return repr(self.data)
try:
raise ErrorInCode(1000)
except ErrorInCode as ae:
print ("0",ae.data)
finally:
print ("1")
Answer
Correct Answer:
1000
1
1000
1
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
176. What will be the correct output of the following Python code?
import math
a = 3.4536
print ("Result = ",end="")
print (math.trunc(a)+math.ceil(a)+math.floor(a))
Answer
Correct Answer:
Result = 10
Note: This Question is unanswered, help us to find answer for this one
Check Answer
177. Find the output of the following Python code and choose the correct answer from the options given below.
tp1 = ('Python',)
m = 5
for i in range(int(m-1)):
(('Python',),)
((('Python',),),)
(((('Python',),),),)
((((('Python',),),),),)
(((((('Python',),),),),),)
('Python',)
('Python',)
('Python',)
('Python',)
('Python',)
('Python')
('Python')
('Python')
('Python')
(('Python',),)
((('Python',),),)
(((('Python',),),),)
((((('Python',),),),),)
Answer
Correct Answer:
(('Python',),)
((('Python',),),)
(((('Python',),),),)
((((('Python',),),),),)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
178. What will be the correct output of the following Python code?
a = 1
def f():
print (a+2)
def g():
a = 2
print (a+1)
def h():
global a
a = 3
print (a+3)
print (a+4)
f()
print (a+2)
g()
print (a+1)
h()
print (a+2)
Code will give a compilation error
Note: This Question is unanswered, help us to find answer for this one
Check Answer
179. Choose the correct output of the following Python code from the given options.
set1 = set()
set2 = set()
for i in range(2, 6):
set1.add(i)
for i in range(4, 7):
set2.add(i)
print("Set1 = ", set1)
print("Set2 = ", set2)
set3 = set1 | set2
set4 = set1 & set2
print(set4)
if set3 > set4:
print("0")
elif set3 < set4:
print("2")
else :
print("1")
if set4 < set3:
print("0")
set5 = set3 - set4
print(set5)
if set4.isdisjoint(set5):
print("1")
set5.clear()
print(set5)
Set1 = {2, 3, 4, 5}
Set2 = {4, 5, 6}
{4, 5}
0
0
{2, 3, 6}
1
set()
Set1 = {2, 3, 4, 5, 6}
Set2 = {4, 5, 6, 7}
{4, 5}
0
0
{2, 3, 6}
1
set()
Set1 = {2, 3, 4, 5}
Set2 = {4, 5, 6}
{4, 5}
1
0
{2, 3, 6}
0
set()
Set1 = {2, 3, 4, 5, 6}
Set2 = {4, 5, 6, 7}
{4, 5}
1
{2, 3, 6}
1
0
set()
Answer
Correct Answer:
Set1 = {2, 3, 4, 5}
Set2 = {4, 5, 6}
{4, 5}
0
0
{2, 3, 6}
1
set()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
180. Upon creation of the 'dumbdbm' database, files with which of the given extensions are created?
dat
dbm
bin
dir
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
181. What will be the correct output of the following Python code?
value = [2, 3, 4, 5, 6]
cd = 0
try:
cd = value[3]
except IndexError:
print('0', end = '') except: print('1', end = '') finally: print('0', end = '') cd = 10 try: cd = cd/0 except ZeroDivisionError: print('1', end = '') finally: print('0')
Note: This Question is unanswered, help us to find answer for this one
Check Answer
182. Find the correct output of the following Python code.
def req(str):
p=2
str = str.split()
str2 = []
for i in str:
if i not in str2:
str2.append(i)
for i in range(0, len(str2)):
p=str.count(str2[i])+p
print(p)
def main():
str =str ='apple mango apple orange orange apple guava mango mango' req(str) if __name__=="__main__": main() ">
Note: This Question is unanswered, help us to find answer for this one
Check Answer
183. What will be the correct output of the following Python code?
lis = [11, 22, 33]
lis1 = [14, 5, 6]
lis2= lis + lis1
print (end="")
for i in range(0,len(lis2)):
print (lis2[i]*1, end=" ")
print ("\r")
lis3 = lis * 2
print (end="")
for i in range(0,len(lis3)):
print (lis3[i]+1, end=" ")
11 22 33 14 5 6
12 23 34 12 23 34
11 22 33 14 5 6
11 22 33 11 22 33
11 22 33 14 5 6
14 5 6 12 23 34
No output will be displayed.
Answer
Correct Answer:
11 22 33 14 5 6
12 23 34 12 23 34
Note: This Question is unanswered, help us to find answer for this one
Check Answer
184. Find the output of the following Python code and choose the correct answer from the given options.
class St:
stm = stm = 'B' def __init__(self, n, r): self.n = n self.r = r a = St("D", 3) print (a.stm) St.stm = "D" b = St("A", 4) print (a.stm) print (b.stm)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
185. What will be the correct output of the following Python language code?
def ps(a,b = 2):
return a + b
a=8
s1 = 1
i = 1
while i <= a:
s1 = s1 + i *2
i = i+1
print(ps(a=1) + ps(a=1, b=3)+s1)
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
186. What would be the output of the Python code given in the image?
JammyPython 3.4.2 # 1siera
RPython 3.4.2 # 2siera
SPython 3.4.2 # 3siera
JammyPython 3.4.2 # 1John
PPython 3.4.2 # 2John
QPython 3.4.2 # 3John
JammyPython 3.4.2 # 1siera
PPython 3.4.2 # 2John
QPython 3.4.2 # 3John
JammyPython 3.4.2 # 1John
RPython 3.4.2 # 2siera
SPython 3.4.2 # 3siera
JammyPython 3.4.2 # 1siera
PPython 3.4.2 # 2siera
QPython 3.4.2 # 3siera
JammyPython 3.4.2 # 1John
RPython 3.4.2 # 2John
SPython 3.4.2 # 3John
JammyPython 3.4.2 # 1siera
RPython 3.4.2 # 2John
SPython 3.4.2 # 3John
JammyPython 3.4.2 # 1John
PPython 3.4.2 # 2siera
QPython 3.4.2 # 3siera
Answer
Correct Answer:
JammyPython 3.4.2 # 1siera
PPython 3.4.2 # 2siera
QPython 3.4.2 # 3siera
JammyPython 3.4.2 # 1John
RPython 3.4.2 # 2John
SPython 3.4.2 # 3John
Note: This Question is unanswered, help us to find answer for this one
Check Answer
187. What will be the correct output of the given Python code?
tuple1 = (0 ,1, 2, 3)
print(tuple1[1:])
print(tuple1[::-1])
print(tuple1[2:4])
(0, 1, 2, 3)
(3, 2, 1, 0)
(3)
(1, 2, 3)
(3, 2, 1, 0)
(2, 3)
No output will be displayed.
Answer
Correct Answer:
(1, 2, 3)
(3, 2, 1, 0)
(2, 3)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
188. While working with MySQL database in Python, which of the following statements is/are correct about the fetchone() method?
1. It is used for fetching the next row of a query result set.
2. It is used for returning the number of rows that were affected by an execute() method.
3. It is used for fetching only the first or the last row of a query result set.
Answer
Correct Answer:
Only option 1.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
189. Analyse the given Python code and answer the question that follows.
def prt2(n):
y=0
k = 2*n - 2
for i in range(0, n):
for j in range(0, k):
print(end=" ")
k = k - 2
for j in range(0, i+1):
y=y+k
return(y)
def prt3(m):
if m > 1:
for i in range(2,m):
if (m % 3) == 0:
print("failure")
break
else:
print("success")
else:
print("failure")
n = 5
m=prt2(n)
k=prt3(m-3)
How many times the word "success" will be printed in the output, when the above code is executed?
Note: This Question is unanswered, help us to find answer for this one
Check Answer
190. This question is based on the graphic shown below.
What will be the correct output of the given Python 3.4.2 code?
No exception
No exception
No exception
division by zero!
No exception
Answer
Correct Answer:
No exception
No exception
No exception
Note: This Question is unanswered, help us to find answer for this one
Check Answer
191. Which of the following databases can be used with Python?
1. MySQL
2. Oracle
3. Maria DB
4. Microsoft SQL Server
All options 1, 2, 3, and 4
Only options 1, 2, and 4.
Only options 2, 3, and 4.
Answer
Correct Answer:
All options 1, 2, 3, and 4
Note: This Question is unanswered, help us to find answer for this one
Check Answer
192. In Python, while developing a program, if you know the place where the code is to be written, but at a later stages, then which of the following control statements will you use?
Answer
Correct Answer:
Pass statement
Note: This Question is unanswered, help us to find answer for this one
Check Answer
193. Find the output of the following Python code and choose the correct answer from the given options.
import multiprocessing
def enr(conn, msgs):
for msg in msgs:
conn.send(msg)
print("{}".format(msg))
conn.close()
def cer(conn):
while 1:
msg = conn.recv()
if msg == "Hi":
break
print("{}".format(msg))
if __name__ == "__main__":
msgs = ["hello", "hey", "hru?", "Hi"]
parent_conn, child_conn = multiprocessing.Pipe()
p1 = multiprocessing.Process(target=enr, args=(parent_conn,msgs))
p2 = multiprocessing.Process(target=cer, args=(child_conn,))
p1.start()
p2.start()
p1.join()
p2.join()
hello
hey
hru?
hello
hey
hru?
Hi
hello
hey
hru?
Hi
hello
hey
Hru?
Code will give a compilation error.
Answer
Correct Answer:
hello
hey
hru?
Hi
hello
hey
Hru?
Note: This Question is unanswered, help us to find answer for this one
Check Answer
194. What will be the correct output of the following Python language code?
import multiprocessing
result = []
def s_p(mp):
global result
for num in mp:
result.append(num * num+1)
print("{}".format(result))
if __name__ == "__main__":
mp = [1,2,3,4]
p1 = multiprocessing.Process(target=s_p, args=(mp,))
p1.start()
p1.join()
print("{}".format(result))
[2, 5, 10, 17] []
[2, 5, 10, 17]
[1, 2, 3, 4, 2, 5, 10, 17]
[1, 2, 3, 4, 2, 5, 10, 17] []
Answer
Correct Answer:
[2, 5, 10, 17] []
Note: This Question is unanswered, help us to find answer for this one
Check Answer
195. In Python, which of the following options is the correct exception that is raised when the next() method of an iterator does not point to any object?
SystemExit
StandardError
StopIteration
None of the above.
Answer
Correct Answer:
StopIteration
Note: This Question is unanswered, help us to find answer for this one
Check Answer
196.
Find the output of the python code given in Figure 1 of the image and choose the correct answer from
the options given in Figure 2 of the same image.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
197.
The Python code given as Figure1 in the image was supposed to give the output that is shown as
Figure2. However. it has some errors. Choose the correct lines number that contain errors.
Answer
Correct Answer:
Line 4.5.10. and 14
Note: This Question is unanswered, help us to find answer for this one
Check Answer
198. This question is based on the graphic shown below.
Analyse the Python code given in Figure 1 of the image and choose the correct answer from the options given in Figure 2 of the same image.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
199. This question is based on the graphic shown below.
If the id's of 'a1', 'a2' and 'a3' in the given Python code are 3012123901, 3012123902 and 3012123903 respectively, then what will be the output of the code?
3012123901 3012123901 3012123901
ajus angee
3012123901 3012123902 3012123901
ajus angee
ajus angee
Answer
Correct Answer:
ajus angee
ajus angee
Note: This Question is unanswered, help us to find answer for this one
Check Answer
200.
This question is based on the graphic shown below.
Consider the Python code in Figure 1 of the given image and choose its correct output from Figure 2.
0.00
(b 0.02
(c)
This question is based on the graphic shown below.
In Python 3.4.2 shell, what will be the output of the given code?
[-1, 435, 1123.5, 5678.2]
Answer
Correct Answer:
[-1, 1, 1123.5, 5678.2]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
201. Find the output of the following Python code and choose the correct answer from the given options.
ast = [2, 1, 3, 5, 3, 8]
ast.sort()
print (end="")
for i in range(0, len(ast)):
print(ast[i]*2, end=" ")
print("\r")
ast.reverse()
print (end="")
for i in range(1, len(ast)):
print(ast[i]+3, end=" ")
2 4 6 6 10 16
11 8 6 6 5 4
Answer
Correct Answer:
2 4 6 6 10 16
8 6 6 5 4
Note: This Question is unanswered, help us to find answer for this one
Check Answer
202. In relation to the exceptions in Python, which of the given exceptions is raised when an identifier is NOT found in the global or local namespace?
LookupError
IndexError
KeyError
NameError
Answer
Correct Answer:
NameError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
203. When does the string method: isalnum() return true?
When the string contains at least one character and all the characters in it are alpha-numeric.
When the string is empty.
When the string contains alphabetical characters along with at least one special character.
When the string contains numeric characters along with at least one special character.
Answer
Correct Answer:
When the string contains at least one character and all the characters in it are alpha-numeric.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
204. Which of the following lines of code results in a compilation error?
1. c1 = { 'A' : 'B', 'C' : 19 }
2. c2 = { 'ID' , 47 }
3. sequ = ('A', 'C', 'D')
4. c1.update(c2)
5. print (str(c1))
6. ct = dict.fromkeys(sequ,5)
7. print (str(ct))
Answer
Correct Answer:
Line number 1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
205. This question is based on the graphic shown below.
What will be the correct output of the given Python code?
Answer
Correct Answer:
rnoysadI6
Note: This Question is unanswered, help us to find answer for this one
Check Answer
206. What will be the correct output of the following Python code?
def f():
print (s)
s = "Me too."
print (s)
s = "Hi"
f()
print (s)
Hi
Hi
Code will give a compilation error.
Answer
Correct Answer:
Hi
Hi
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
207. What will be the correct output of the following Python code?
import bisect
# initializing list
li = [1, 3, 4, 4, 4, 6, 7]
print ("Output = ", end="")
print (bisect.bisect(li, 4)+bisect.bisect_left(li, 4)+bisect.bisect_right(li, 4, 0, 4))
Answer
Correct Answer:
Output = 11
Note: This Question is unanswered, help us to find answer for this one
Check Answer
208. What will be the correct output of the following Python code?
try:
x = 11
Hx>8z
y = x/(X-3)
print (y)
exceptaeroDivisionError, NameError):
print ("1")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
209. What will be the correct output of the following Python code?
x = 5.2
x **= 3
print(x)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
210. This question is based on the graphic shown below.
Choose the correct output of the given Python code.
Answer
Correct Answer:
Angee
Angee
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
211. Consider the Python 3.4.2 code that is given in the image. Choose the correct line(s) number from the
following options that will not give an output as "None".
Answer
Correct Answer:
Line number 11
Note: This Question is unanswered, help us to find answer for this one
Check Answer
212. This question is based on the graphic shown below.
The Python code given in Figure 1 of the image was supposed to give the output that is given in Figure 2, but lines number 14 and 24 are coded incorrectly. Choose the correct lines from the following options that will replace both the lines to obtain the desired output.
Line 14: a -= 1
Line 24: while e>=1
Line 14: a += 1
Line 24: while d>=1
Line 14: a += 1
Line 24: while e>=1:
Line 14: a -= 1
Line 24: while d>=1:
Answer
Correct Answer:
Line 14: a += 1
Line 24: while e>=1:
Note: This Question is unanswered, help us to find answer for this one
Check Answer
213. In relation to the exceptions in Python, which of the given exceptions is raised when a generated error code does not fall into any category?
Answer
Correct Answer:
RuntimeError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
214. Find the output of the following Python code and choose the correct answer from the given options.
n1 = 1.5
n2 = 6.3
s = float(n1) + float(n2)
print('{0}'.format(s))
s //= 3
print(s)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
215. What will be the correct output of the following Python language code?
def square(n):
return (n‘n+1)
if _name_ = "_main__":
mt = [1,2,3,4,5,0]
rt = []
for num in mt:
rt.append(square(num‘2)+1‘4)
printlrt)
Answer
Correct Answer:
[8. 20. 41. 68.104.4]
[8, 20,40. 68,104, 0]
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
216.
What would be the output of the given Python code. when executed?
output: [5. 4, 3, [11. 22, 31. 41]]
output: [5. 4, 3. [11. 22. 31. 41]]
output: [11.22.31.41[5.4. 31]
output: [11.22.31.41 [5.4.31]
output: [5. 4. 3]
output“ [11. 22, 31. 41]
output: [11. 22. 31. 41]
output: [5. 4. 3]
Answer
Correct Answer:
output: [11. 22. 31. 41]
output: [5. 4. 3]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
217. Analyse the given Python code and answer the question that follows.
import math
a = math.pi/6
b = 3
c = 4
print (math.tan(a))
print ("result = ", end="")
print (math.hypot(b,c))
What will be the correct output of the above Python code?
4773502691896257
result = 4.0
5773502691896257
result = 5.0
6773502691896257
result = 6.0
7773502691896257
result = 7.0
Answer
Correct Answer:
5773502691896257
result = 5.0
Note: This Question is unanswered, help us to find answer for this one
Check Answer
218. The items() method in Python is used for returning the list with all dictionary keys and values.
True
False
Note: This Question is unanswered, help us to find answer for this one
Check Answer
219. Analyse the given Python code and choose the correct output from the given options.
pdata = 50
try:
pdata = pdata/0
except ZeroDivisionError:
print('0 ', end = '') else: print('1', end = '') try: pdata = pdata/5 except: print('1', end = '') else: print('0', end = '')
Note: This Question is unanswered, help us to find answer for this one
Check Answer
220. What will be the correct output of the following Python code?
def KToFiTemp):
assert (Temp >= 0),"Colder than absolute zero!"return ((Temp-273)‘1.8)+32
print KToF(273)
print int(KToF(505.78))
print KToF(-5)
32.0
451
Colder than absolute zero!
32
451.0
Colder than absolute zero!
Code will give a compilation error.
Answer
Correct Answer:
Code will give a compilation error.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
221. Which of these answers will create a list that looks like this: ["2","2","2"]?
theList = [2] * 3 0.0
theList = [
theList = [
theList = [3] *
Answer
Correct Answer:
theList = [2] * 3 0.0 theList = [
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
222.
Which is the best possible way of getting the local ip address using stdlib of python?
import socket socket.gethostbyname(socket.gethostname())
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("gmail.com",80)) print(s.getsockname()[0])
import socket print([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1])
None of the above
Answer
Correct Answer:
import socket socket.gethostbyname(socket.gethostname())
Note: This Question is unanswered, help us to find answer for this one
Check Answer
223.
How can a list of dictionaries be sorted by the values of the dictionaries?
from operator import itemgetter sortedlist = sorted(a_list_of_dicts, key = itemgetter('name'))
import operator sortedlist = a_list_of_dicts.sort(key = operator.itemgetter('name'))
def mykey(adictionary): return adictionary['name'] sortedlist = sorted(a_list_of_dicts, key=mykey)
sortedlist = a_list_of_dicts.sort(lambda x,y : cmp(x['name'], y['name']))
Answer
Correct Answer:
from operator import itemgetter sortedlist = sorted(a_list_of_dicts, key = itemgetter('name'))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
224.
What is the output of the following? t=(1,2,4,3,5) print(t[1:3])
(1, 4)
(1, 4, 3)
(2, 4)
(2, 4, 3)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
225.
What will be the output of following code? def val1(param): return param def val2(param): return param * 2 def val3(param): return param + 5 result = val1(val2(val3(1))) print(result)
8
12
10
6
Note: This Question is unanswered, help us to find answer for this one
Check Answer
226.
Which of the following will be the output of the below code snippet? x = [] y = x y.append(10) z = 5 w = z z = z - 1 print(y) print(x) print(z) print(w)
[10] [] [4] [5]
[10] [10] [4] [5]
[10] [[10]] [5] [5]
[10] [None] [5] [4]
Answer
Correct Answer:
[10] [10] [4] [5]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
227.
Boolean
Integer
Float
Complex
Note: This Question is unanswered, help us to find answer for this one
Check Answer
228.
Which of the following snippets will return the list of all occurances of 'b' in a = ['a','b','c','b'] ?
b = [item for item in a if a == 'b'][0]
b = [item for item in a if a[] == 'b']
b = [item for item in a if 'b' in a]
b = [item for item in a if item == 'b']
Answer
Correct Answer:
b = [item for item in a if 'b' in a]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
229.
What will be the output of the following? my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] new_list = list(filter(lambda x: (x%2 == 0) , my_list)) print(new_list)
[1, 3, 5, 6, 9]
[1, 5, 7, 9, 10]
[2, 4, 6, 8, 10]
[0, 4, 6, 8, 10]
Answer
Correct Answer:
[2, 4, 6, 8, 10]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
230.
What will be the output of the code below? s = 'messha' for i in range(len(s)): print(i)
m e s s h a
0 1 2 3 4 5
6
5
Answer
Correct Answer:
0 1 2 3 4 5
Note: This Question is unanswered, help us to find answer for this one
Check Answer
231.
What will be the output of following code? items = set() items.add("google") items.add("apple") items.add("microsoft") print(items)
set(['google', 'apple', 'microsoft'])
set['google', 'apple', 'microsoft']
set('google', 'apple', 'microsoft')
set{'google', 'apple', 'microsoft'}
Answer
Correct Answer:
set(['google', 'apple', 'microsoft'])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
232.
What command is used to get the hostname of the computer the Python script is running on?
print hostname()
import socket print gethostname()
print socket.gethostname()
import socket print socket.gethostname()
Answer
Correct Answer:
import socket print socket.gethostname()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
233.
Regarding the code below, what's correct statement ? class Book: def __init__(self, isbn): self.isbn = isbn isbn = 'test' book = Book(12345)
book.isbn will contain the value 12345.
book.isbn will contain the value 'test'.
This program won't run the Book class expects a string instead of integer.
None of the above is correct.
Answer
Correct Answer:
book.isbn will contain the value 12345.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
234.
Which of the following statements are true regarding __slots__ in Python?
__slots__ can be useful when many small object creations are needed, with predefined structures and with memory limitations.
__slots__ is an optimized dynamic structure.
__slots__ is a memory optimization tool.
__slots__ breaks multiple inheritance.
Answer
Correct Answer:
__slots__ is an optimized dynamic structure. __slots__ is a memory optimization tool.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
235.
Suppose we have a User class, how do we make a new User object?
a = new User()
User a = new User()
User.new(Object)
a = User()
Answer
Correct Answer:
a = User()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
236.
What would the output of the following code be: def a(): print "a executed" return [] def b(x=a()): x.append(5) x.append(1) print x b() b() b()
a executed [1] a executed [1, 1] a executed [1, 1, 1]
a executed [5, 1] [5, 1, 5, 1] [5, 1, 5, 1, 5, 1]
a executed [5, 1] [5, 1] [5, 1]
a executed [5, 1] a executed [5, 1] a executed [5, 1]
a executed [5, 1] a executed [5, 1, 5, 1] a executed [5, 1, 5, 1, 5, 1]
Answer
Correct Answer:
a executed [5, 1] a executed [5, 1] a executed [5, 1]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
237.
Regarding Unicode in Python 3, which of the following is incorrect ?
The `str` type contains Unicode characters, meaning any string created using "unicode rocks!", 'unicode rocks!', or the triple-quoted string syntax is stored as Unicode.
One can create a string using the `decode()` method of `bytes` type, and it will use by default 'latin_1' encoding.
Python 3 supports using Unicode characters in identifiers.
One can create a byte representation from a string by using the `encode()` method, and it will use by default 'utf-8' encoding.
Answer
Correct Answer:
One can create a string using the `decode()` method of `bytes` type, and it will use by default 'latin_1' encoding.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
238.
Which of the following statements are correct about assertions in Python?
Asserts are used to control program flow.
The "assert" statements are removed when the compilation is optimized.
Asserts should be used to test conditions that should never happen.
Asserts are used to define custom exceptions that are to be caught.
Answer
Correct Answer:
The "assert" statements are removed when the compilation is optimized. Asserts should be used to test conditions that should never happen.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
239.
Suppose a database table row has to be represented, and a field needs to be accessed via its field name or field index; which of the following data types suits this purpose best?
dict
OrderedDict
list
namedtuple
Answer
Correct Answer:
namedtuple
Note: This Question is unanswered, help us to find answer for this one
Check Answer
240.
How to get access to _b in outside of class a?
a.__b_
a._a__b
b.__a
None of the above
Answer
Correct Answer:
None of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
241.
Consider the Python function: def secret_function(sPath): import os for sChild in os.listdir(sPath): sChildPath = os.path.join(sPath,sChild) if os.path.isdir(sChildPath): secret_function(sChildPath) else: print(sChildPath) What would be the most correct statement to describe above function?
This function takes the name of a directory and prints out the absolute paths for the files and sub-directories.
This function takes the name of a directory and prints out the paths files within that directory as well as any files contained in contained directories.
This function takes the name of a directory and prints out the paths for the files and sub-directories.
This function will get stuck in the recursive calls and will eventually throw a runtime error.
Answer
Correct Answer:
This function takes the name of a directory and prints out the paths files within that directory as well as any files contained in contained directories.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
242.
Regarding Thread Synchronization Primitives in Python, which of the following is incorrect ?
Mutual Exclusion Lock (`threading.Lock`) are used to synchronize threads so that only one thread can make modifications to shared data at any given time. Only one thread can successfully `acquire()` the lock at any given time.
Reentrant Mutex Lock (`threading.RLock`) are similar to a normal mutex lock except that it can be reacquired multiple times by the same thread.
Semaphores (`threading.Semaphore`) are counter-based synchronization primitive, `acquire()/release()` increments or decrements a internal counter, and like locks, cannot be called in any order and by any thread.
Event Objects (`threading.Event`) can be used to have one or more threads wait for something to occur. Setting an event will unblock all waiting threads simultaneously (if any).
Answer
Correct Answer:
Semaphores (`threading.Semaphore`) are counter-based synchronization primitive, `acquire()/release()` increments or decrements a internal counter, and like locks, cannot be called in any order and by any thread.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
243.
Which option in sqllite.connect() method avoids OperationalError telling that the database file is locked?
check_same_thread
check_thread
check_diff_thread
check_same_threads
Answer
Correct Answer:
check_same_thread
Note: This Question is unanswered, help us to find answer for this one
Check Answer
244.
From the following which is not a good recommendation for Threading in Python?
Use multitasking module
use Queue.Queue
Use an event model, such as Twisted
Use the threading module
Answer
Correct Answer:
use Queue.Queue
Note: This Question is unanswered, help us to find answer for this one
Check Answer
245.
Which of the following statement is incorrect regarding Concurrency in Python?
A Thread can be defined by subclassing the `threading.Thread` and overriding the method `run()`
A Thread instance is launched when the method `begin()` from `threading.Thread` is called.
Once you start a Thread, it runs independently, and one can use `join()` to wait for a thread to exit
Threads share all of the data in your program, and access to shared variables may cause so called Race Conditions, which can be resolved with synchronization primitives such as Mutex Locks.
Answer
Correct Answer:
A Thread instance is launched when the method `begin()` from `threading.Thread` is called.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
246.
Considering this Python 2.x snippet, while(True): try: doWork() except TypeError: print 'Type error' except Exception: print 'General exception' except GeneratorExit, KeyboardInterrupt: print 'Existing exception' which of the following is correct to say?
If doWork() raise a TypeError, then the program will print 'General exception', as TypeError is subclass of Exception.
If the user tries to exit the program by entering Ctrl + C from the keyboard, the program won't stop as KeyboardInterrupt is being handled and not re-raised.
KeyboardInterrupt is the instance name for the exception class GeneratorExit. Therefore KeyboardInterrupt is never handled on this code.
No matter what exception happens, the program will not stop and will print 'General exception' in the console, as Exception is the first base class in the Python exception hierarchy.
Answer
Correct Answer:
KeyboardInterrupt is the instance name for the exception class GeneratorExit. Therefore KeyboardInterrupt is never handled on this code.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
247.
Which of the following is true regarding urlopen function from the standard module urllib in Python 2?
Open a network object denoted by a URL for reading, but it cannot be used to open local files.
If the connection cannot be made the LookupError exception is raised.
If the connection is successful, this function returns the content of the object as string.
When opening HTTPS URLs, it does not attempt to validate the server certificate.
Answer
Correct Answer:
If the connection cannot be made the LookupError exception is raised.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
248.
Which of the following statement is incorrect regarding Python language?
Python is an interpreted language. That means that, unlike languages like C and its variants, Python does not need to be compiled before it is run.
Python is dynamically typed, this means that you don't need to state the types of variables when you declare them or anything like that.
Python is well suited to object orientated programming in that it allows the definition of classes along with composition and inheritance.
In Python, functions are not objects. This means that they cannot be assigned to variables, returned from other functions and passed into functions.
Answer
Correct Answer:
In Python, functions are not objects. This means that they cannot be assigned to variables, returned from other functions and passed into functions.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
249.
Which of the following is false regarding urlretrieve function from the standard module urllib in Python 2?
It copies a network object denoted by a URL to a local file, if necessary.
If the target URL points to a local file, or a valid cached copy of the object exists, the object is not copied.
It returns a tuple (filename, headers, filesize) where filename is the local file name under which the object can be found.
It's possible to define a custom path for the local file, where the object will be saved.
Answer
Correct Answer:
It returns a tuple (filename, headers, filesize) where filename is the local file name under which the object can be found.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
250.
Regarding Secure hashes and message digests in Python 3 using standard module hashlib, which of the following is true ?
hashlib.sha224(b"test") will return the sha224 hash (as string) of the value "test".
`hexdigest()` function will return a hexadecimal string representation of the underlying hash algorithm.
Feeding string objects into update() is supported, as hashes work on both bytes and strings.
Answer
Correct Answer:
`hexdigest()` function will return a hexadecimal string representation of the underlying hash algorithm.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
251.
Which of the following is incorrect to say about CPython's garbage collection mechanism ?
Python maintains a count of the number of references to each object in memory. If a reference count goes to zero then the associated object is no longer live and the memory allocated to that object can be freed up for something else.
The garbage collector periodically looks for "reference cycles" and cleans them up. An example would be if you have two objects o1 and o2 such that o1.x == o2 and o2.x == o1. If o1 and o2 are not referenced by anything else then they shouldn't be live. But each of them has a reference count of 1.
The garbage collector is a deterministic process, so that heuristics are never used to improve performance of garbage collection.
All of the above are correct.
Answer
Correct Answer:
The garbage collector is a deterministic process, so that heuristics are never used to improve performance of garbage collection.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
252.
Which of the following is NOT correct regarding unittest in Python 3?
Each test case must be defined inside a class that inherits from unittest.TestCase
@unittest.skip is a decorator designed to disable the specific test unit from running.
setUp() from unittest.TestCase can be overridden and is called immediately before calling the test method.
tearDown() from unittest.TestCase is called only once per class, immediately before the first test method.
Answer
Correct Answer:
tearDown() from unittest.TestCase is called only once per class, immediately before the first test method.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
253.
In Python 3, which of the following is correct regarding data types Lists, Tuples, Dictionaries and Sets ?
`add()` from a Dictionary object will add a new key-value pair to the end of the collection.
If `a_set` is a Set instance, then `a_set.difference(a_set)` will always return an empty Set object.
To add a new object to the end of a Tuple, one can use the method `append()`.
List objects do not have a `pop()` method as this is typical of Stack data type.
Answer
Correct Answer:
If `a_set` is a Set instance, then `a_set.difference(a_set)` will always return an empty Set object.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
254.
In Python 3, which of the following is incorrect regarding data structures ?
Lists are ordered collections that can hold arbitrary objects and can expand dynamically as new items are added.
Tuples are ordered collections that can hold arbitrary objects, but are immutable.
A set is an unordered collection of unique values and support standard Set operations such as union, intersection, and difference.
A Dictionary is an unordered set of key-value pairs, but becomes essentially immutable once a key already exists.
Answer
Correct Answer:
A Dictionary is an unordered set of key-value pairs, but becomes essentially immutable once a key already exists.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
255.
Considering Python 2.5, what will be the output of following code? fp = None with open('file.data', 'r') as fp: cont = f.read() print fp.closed
True
False
None
It raises AttributeError: object has no attribute 'closed'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
256.
Which of the following statements regarding tuples and lists is wrong?
Lists are mutable while tuples are immutable, and cannot be modified once created.
Tuples are hashable and can be used as dictionary keys, lists are not.
Tuples usually contain a heterogeneous sequence of elements that are accessed via unpacking, but not indexing.
Elements of lists are usually homogeneous and are accessed by iterating over the list.
Answer
Correct Answer:
Tuples usually contain a heterogeneous sequence of elements that are accessed via unpacking, but not indexing.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
257.
Which of the following can be used to check if a value is an int? The value is a = 10
type(a) is int
isinstance(a, int)
issubclass(type(a), int)
All of these
Answer
Correct Answer:
isinstance(a, int)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
258.
Which of the following method is used to get the name of a thread?
getName()
getthread()
getThread()
get_id()
Answer
Correct Answer:
getName()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
259.
Which of the following is the correct way to print a list called theList in reverse order?
for i in reversed(theList): print i
for i in theList[:-1]: print i
for i in theList.reversed: print i
for i in reversed(theList)[-1:]: print i
Answer
Correct Answer:
for i in reversed(theList): print i
Note: This Question is unanswered, help us to find answer for this one
Check Answer
260.
What is the type of each element in sys.argv ?
array
string
tuple
list
Note: This Question is unanswered, help us to find answer for this one
Check Answer
261.
An object can contain?
variables
methods
functions
variables and methods
Answer
Correct Answer:
variables and methods
Note: This Question is unanswered, help us to find answer for this one
Check Answer
262.
Which is the best way to convert a Python time.struct_time object into a datetime object?
structTime = time.localtime() datetime.datetime(*structTime[:6]) datetime.datetime(2009, 11, 8, 20, 32, 35)
datetime.fromtimestamp(mktime(struct))
A time.struct_time object cannot be converted into a datetime object.
datetime.fromtimestamp(struct)
Answer
Correct Answer:
datetime.fromtimestamp(mktime(struct))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
263.
What is the type of x? x = 10.0//5
int
float
long
number
Note: This Question is unanswered, help us to find answer for this one
Check Answer
264.
In Python, a string literal is enclosed in _____?
parentheses
brackets
single-quotes
double-quotes
Answer
Correct Answer:
single-quotes double-quotes
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
265.
What gets printed on the console for the following Python 2.x code? A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5))) A1 = range(5) A2 = sorted([i for i in A1 if i in A0]) A3 = sorted([A0[s] for s in A0]) A4 = [i for i in A1 if i in A3] A5 = {i:i*i for i in A1} A6 = [[i,i*i] for i in A1] print A6
[[0, 0], [1, 1], [2, 4], [3, 9], [4, 16]]
[{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}]
[[1, 2, 3, 4, 9, 16]]
[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]
Answer
Correct Answer:
[[0, 0], [1, 1], [2, 4], [3, 9], [4, 16]]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
266.
_____ measures how full the hash table is?
Load factor
Threshold
Dump
Tuple
Answer
Correct Answer:
Load factor
Note: This Question is unanswered, help us to find answer for this one
Check Answer
267.
How to convert a json string to Python object?
simplejson.load()
json.load()
json.dumps()
json.loads()
Answer
Correct Answer:
json.loads()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
268.
Which one of these answers will catch an exception, but do nothing with it?
doSomething()
try: doSomething()
try: doSomething() except:
try: doSomething() except: pass
Answer
Correct Answer:
try: doSomething() except: pass
Note: This Question is unanswered, help us to find answer for this one
Check Answer
269.
Which of the following can be used to create a directory?
os.make_dir()
os.create_dir()
os.mkdir()
All of the above
Answer
Correct Answer:
os.mkdir()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
270.
Which of the following is the correct way to change the current working directory in Python?
import os os.chdir("/path/to/change/to")
os.chdir("/path/to/change/to")
chdir("/path/to/change/to")
import os os.cd("/path/to/change/to")
Answer
Correct Answer:
import os os.chdir("/path/to/change/to")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
271.
What is the correct way to increment the value of the variable "i" by 1?
i += 1
i++
++i
inc(i)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
272.
Which of the following will remove duplicate elements from a list (O(n)), whilst preserving order?
mylist = [x for i,x in enumerate(mylist) if x not in mylist[i+1:]]
mylist = reduce(lambda x, y: x if y in x else x + [y], mylist, [])
seen = set() seen_add = seen.add mylist = [ x for x in mylist if x not in seen and not seen_add(x)]
mylist = [x for i,x in enumerate(mylist) if x not in mylist[:i]]
Answer
Correct Answer:
mylist = [x for i,x in enumerate(mylist) if x not in mylist[i+1:]]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
273.
What will the following code do? somelist[:] = [tup for tup in somelist if determine(tup)]
It will remove duplicates and put them into a new list with the same name.
It will reorder the list depending on occurrence(s).
It will remove duplicates from the list.
It will double the occurrences in the list.
Answer
Correct Answer:
It will remove duplicates from the list.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
274.
Which of the following exception raised for an error that doesn’t fall in any of the categories?
SyntaxError
RuntimeError
SystemError
CodeError
Answer
Correct Answer:
RuntimeError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
275.
What will be the output of the following code? def name(X, Y, Z, **opt): if opt.get("number") == "Y": return Y res = name(1, 2, 3, action = "sum", number = "Y") print "Result: %d" % res
Result: 1
Result: 2
Result: 3
Result: 0
Answer
Correct Answer:
Result: 2
Note: This Question is unanswered, help us to find answer for this one
Check Answer
276.
What gets printed in the code below ? def f(x, l=[]): for i in range(x): l.append(i * i) return l f(2) f(3, [3, 2, 1]) print f(3)
[0, 1, 4]
[0, 1, 0, 1, 4]
[0, 1, 0]
[3, 2, 1, 0, 1, 4]
Answer
Correct Answer:
[0, 1, 0, 1, 4]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
277.
Which of the following will be the output of the below code snippet? class foo: def normal_call(self): print("normal_call") def call(self): print("first_call") self.call = self.normal_call y = foo() y.call() y.call() y.call()
first_call normal_call normal_call
first_call first_call first_call
normal_call normal_call normal_call
first_call normal_call first_call
Answer
Correct Answer:
first_call normal_call normal_call
Note: This Question is unanswered, help us to find answer for this one
Check Answer
278.
Consider the following Python code: test = 1/2 What is the value of 'test' in Python 2.7 and 3.5, respectively ?
0 and 1
0 and 0.5
0.5 and 0
1 and 0
Answer
Correct Answer:
0 and 0.5
Note: This Question is unanswered, help us to find answer for this one
Check Answer
279.
Which of the following is the correct way to determine a variable's type in Python?
type(variable_name)
dir(variable_name)
var(variable_name)
typevar(variable_name)
Answer
Correct Answer:
type(variable_name)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
280.
Which of the following will be the output of the below code snippet? def foo(x=[]): x.append(1) print(x) foo() foo() foo()
[1, 1] [1, 1] [1, 1]
[1, 1, 1] [1, 1, 1] [1, 1, 1]
[1] [1] [1]
[1] [1, 1] [1, 1, 1]
Answer
Correct Answer:
[1] [1, 1] [1, 1, 1]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
281.
What will be the output of following code snippet? def f(x): return x % 2 != 0 and x % 3 != 0 result=filter(f, range(1, 20)) print result
[1, 3, 7, 10, 13, 16, 19]
[1, 6, 9, 11, 15, 17, 19]
[1, 5, 7, 11, 13, 17, 19]
[1, 4, 7, 12, 15, 17, 19]
Answer
Correct Answer:
[1, 5, 7, 11, 13, 17, 19]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
282.
What will be the output of following code? d = lambda p: p * 2 t = lambda p: p * 3 x = 2 x = d(x) x = t(x) x = d(x) print x
7
12
24
36
48
Note: This Question is unanswered, help us to find answer for this one
Check Answer
283.
What will be the output of following code? import threading k = 10 x = 0 m = threading.Lock() def foo(): global x for i in xrange(k): with m: x += 1 def bar(): global x for i in xrange(k): with m: x -= 1 t1 = threading.Thread(target=foo) t2 = threading.Thread(target=bar) t1.start() t2.start() t1.join() t2.join() print x
It will raise an exception.
1
It will randomly print a different value on every run.
Answer
Correct Answer:
It will raise an exception.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
284.
What will be the output of following code? def f2(n, result): if n == 0: return 0 else: return f2(n - 1, n + result) print(f2(2, 0))
0
1
2
3
Note: This Question is unanswered, help us to find answer for this one
Check Answer
285.
The __ function can be used to check if a file f exists?
os.path.isFile(f)
os.path.exists(f)
os.path.isfile(f)
os.isFile(f)
Answer
Correct Answer:
os.path.isfile(f)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
286.
On a Unix-like system, what does Python's sleep.time() function block?
The thread.
The process.
Nothing.
It always blocks both.
Answer
Correct Answer:
The thread.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
287.
sys.path is initialized from which of the following locations ?
The directory containing the input script .
PYTHONPATH enviroment variable.
The installation-dependent default.
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
288.
The side option of the pack manager may be _____?
LEFT
RIGHT
BOTTOM
TOP
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
289.
How to get JSON to load into an OrderedDict in python?
By simply using json.loads(D) where D is Ordered dictionary
By specifying the object_pairs_hook argument to JSONDecoder
Ordered dictionary is not supported yet
By simply using json.dumps(D) where D is Ordered dictionary
Answer
Correct Answer:
By specifying the object_pairs_hook argument to JSONDecoder
Note: This Question is unanswered, help us to find answer for this one
Check Answer
290.
Which method in the following is used to convert raw json objects to Json in python?
json.dumps()
JSONEncoder().encode()
json.loads()
json.default()
Answer
Correct Answer:
json.loads()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
291.
Invoking the ___ method converts raw byte data to a string?
encode()
decode()
convertString()
toString()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
292.
What will be the output of following code? print "\x48\x49!"
HI!
48 49!
4849!
\x48\x49!
4849
Note: This Question is unanswered, help us to find answer for this one
Check Answer
293.
What is the default encoding in the string function encode()?
ascii
utf-8
wtf-8
cesu-8
Note: This Question is unanswered, help us to find answer for this one
Check Answer
294.
What will be the following code output? import math res = math.pow(4, 3) def addition(x, y): return (x+y) def subtract(x, y): return (x-y) def multiply(x, y): return (x*y) def divide(x, y): return (x%y) import mathExample print mathExample.res
64.0
43
4.0
3.0
Note: This Question is unanswered, help us to find answer for this one
Check Answer
295.
Which of the following environment variable for Python is an alternative module search path?
PYTHONCASEOK
PYTHONHOME
PYTHONSEARCH
PYTHONURL
Answer
Correct Answer:
PYTHONHOME
Note: This Question is unanswered, help us to find answer for this one
Check Answer
296.
Considering the following code snippet:- def test (a, b, c): pass Which of the following is a true statement?
It defines a function that will automatically pass to other function the three parameters it receives.
It defines a function that essentially does nothing.
It defines an empty class.
It's a native Python function that tests if any of the parameters evaluates to `True`.
Answer
Correct Answer:
It defines a function that essentially does nothing.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
297.
What will be the output of following code? counter = 1 def count(): global counter t = (1, 2, 3) for i, v in enumerate(t): counter += i + v count() print counter
9
10
11
12
13
Note: This Question is unanswered, help us to find answer for this one
Check Answer
298. Which of the following is a correct way to add a new element to a list?
list.add(1)
list.addValue(1)
list.append(1)
list.addItem(1)
Answer
Correct Answer:
list.append(1)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
299.
A hashing function ____?
stores an element in the hash table
maps a key to an index in the hash table
different index in the hash table
Answer
Correct Answer:
maps a key to an index in the hash table
Note: This Question is unanswered, help us to find answer for this one
Check Answer
300.
What is the output if following code executed? a1 = 0 b2 = 1 c3 = 2 def fru_box(): a1 = b2 + c3 print((a1, '\t', b2, '\t', c3)) return fru_box()
(1, '\t', 2, '\t', 3)
(2, '\t', 1, '\t', 3)
(1, '\t', 3, '\t', 2)
(3, '\t', 1, '\t', 2)
Answer
Correct Answer:
(3, '\t', 1, '\t', 2)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
301.
Which code snippet below will not return True?
1 in [1,0]
1 in [1,0] == True
(1 in [1,0]) == True
1 in [1, 2, 3]
Answer
Correct Answer:
1 in [1,0] == True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
302.
What will be the output of following code? from functools import * def add(a, b, c): return 50*a + 5*b + c res = partial(add, c=2, b=1) print(res(2))
140
150
107
250
Note: This Question is unanswered, help us to find answer for this one
Check Answer
303.
Which of the following will return the size of a file?
import os size = os.stat('somefile.txt') size.st_size
import os size = os.path.getsize('somefile.txt')
import os size = os.filesize('somefile.txt')
import os size = os.fileprop('somefile.txt') size.filesize
Answer
Correct Answer:
import os size = os.stat('somefile.txt') size.st_size import os size = os.path.getsize('somefile.txt')
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
304.
What will be the output of following code? nums = list() i = 3 while (i < 9): nums.append(i) i = i+2 print(nums)
[3, 5, 9]
[3, 2, 7]
[3, 9, 7]
[3, 5, 7]
Answer
Correct Answer:
[3, 5, 7]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
305.
Which of the following is the correct way to empty a list, using theList as an example?
del theList[] = []
theList = []
del theList[:]
del theList[]
Answer
Correct Answer:
del theList[:]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
306.
orig = { '1' : 1, '2' : 2 } a_copy = orig.copy() orig['1'] = 5 sum = orig['1'] + a_copy['1'] print sum What will be printed in the above Python code?
6
1
2
10
None
Note: This Question is unanswered, help us to find answer for this one
Check Answer
307.
What will be the output of following code? def addItem(l): l += [0] mylist = [1, 2, 3, 4, 5] addItem(mylist) print len(mylist)
12345
1234
01234
6
Note: This Question is unanswered, help us to find answer for this one
Check Answer
308.
What is the return value of trunc()?
tuple
float
int
bool
Note: This Question is unanswered, help us to find answer for this one
Check Answer
309.
What function do you use to read a string?
input("Enter a string")
eval(input("Enter a string"))
enter("Enter a string")
print(enter("Enter a string"))
Answer
Correct Answer:
input("Enter a string")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
310.
Which of the following statements would create an instance of Firm class correctly?
Firm = Firm('client', 2000)
Firm = Firm()
Firm = Firm('server', 2000)
None of the above
Answer
Correct Answer:
None of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
311.
Check whether an object x is an instance of class A, use _____.?
x.instance(A)
A.instance(x)
isinstance(x, A)
instance(A, x)
Answer
Correct Answer:
isinstance(x, A)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
312.
Consider the code, and choose the correct statement: class A: def __init__(self, i = 0): self.i = i class B(A): def __init__(self, j = 0): self.j = j def main(): b = B() print(b.i) print(b.j) main()
Class B inherits A, but the data field i in A is not inherited.
Class B inherits A and automatically inherits all data fields in A.
When you create an object B, you have to pass an integer such as B(5).
The data field j cannot be accessed by object b.
Answer
Correct Answer:
Class B inherits A, but the data field i in A is not inherited.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
313.
Which of the following statements are true?
open a file for reading, if the file does not exist, an error occurs.
open a file for writing, if the file does not exist, an error occurs.
open a file for reading, if the file does not exist, the program will open an empty file.
open a file for writing, if the file does not exist, a new file is created.
open a file for writing, if the file exists, the existing file is overwritten with the new file.
Answer
Correct Answer:
open a file for reading, if the file does not exist, an error occurs. open a file for writing, if the file does not exist, a new file is created. open a file for writing, if the file exists, the existing file is overwritten with the new file.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
314.
What is the output of "Dummy Text is my text".strip('Te') -
'Dummy Text is my text'
'Dummy xt is my xt'
'Dummy xt is my text'
None of these
Answer
Correct Answer:
None of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
315.
Which of the following is incorrect regarding modules in Python?
Each module can only be imported once per interpreter session. And If you change a module the interpreter will automatically reload it for you.
The interpreter searches for a module first at the directory of the top-level file, i.e. the file being executed.
`dir(__builtins__)` will return a list of all built-in functions, exceptions, and other objects.
It's possible to put several modules into a Package. A directory of Python code is said to be a package.
Answer
Correct Answer:
Each module can only be imported once per interpreter session. And If you change a module the interpreter will automatically reload it for you.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
316.
What is the result of the following code: listOne = [1, 3, 5] listTwo = [2, 4, 6] listNew = listOne + listTwo print listNew
[3, 7, 11]
[1, 2, 3, 4, 5, 6]
[1, 3, 5, 2, 4, 6]
[ [1, 3, 5], [2, 4, 6] ]
Answer
Correct Answer:
[1, 2, 3, 4, 5, 6]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
317.
Which of the following are the characteristics of the __init__.py file?
__init__.py can be an empty file, but it can also execute initialization code for the package or set the __all__ variable.
The __init__.py files are used to override the classes' initializations globally.
The __init__.py files are required to make Python treat the directories as if they contain packages.
The __init__.py files are used to define the classes' basic initializations.
Answer
Correct Answer:
__init__.py can be an empty file, but it can also execute initialization code for the package or set the __all__ variable. The __init__.py files are used to override the classes' initializations globally. The __init__.py files are required to make Python treat the directories as if they contain packages. The __init__.py files are used to define the classes' basic initializations.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
318.
Which of the following will be the output of the below code snippet? squares = [] for x in range(5): squares.append(lambda: x**2) x = 8 for i in range(5): print(squares[i]())
1 4 9 16 25
64 64 64 64 64
UnboundLocalError: local variable 'x' referenced before assignment
64 4 9 16 25
Answer
Correct Answer:
64 64 64 64 64
Note: This Question is unanswered, help us to find answer for this one
Check Answer
319.
Which piece of code best describes the way to parse data from JSON file?
import json from pprint import pprint with open('data.json') as data_file: data = json.load(data_file) pprint(data)
import json from pprint import pprint json_data=open('json_data') data = json.load(json_data) pprint(data)
data = [] with codecs.open('d:\output.txt','rU','utf-8') as f: for line in f: data.append(json.loads(line))
None of the above
Answer
Correct Answer:
import json from pprint import pprint with open('data.json') as data_file: data = json.load(data_file) pprint(data)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
320.
What will be the output of following code? x, y = 15, 45 res = x if x < y else y print(res)
45
1
Error
15
Note: This Question is unanswered, help us to find answer for this one
Check Answer
321.
Which function do you use to read data using binary input?
write
output
dump
send
Note: This Question is unanswered, help us to find answer for this one
Check Answer
322.
Which of the following will be returned by readlines() method?
str
a list of lines
a list of single characters
a list of integers
Answer
Correct Answer:
a list of lines
Note: This Question is unanswered, help us to find answer for this one
Check Answer
323.
Which built-in Python function can be used to get the length of a list, tuple, string, dictionary or other object?
lengthof()
length()
len()
sizeof()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
324.
Which is correct about getting a free port number?
use sock.getsockname() to get a free port number
Do not bind to a specific port, or bind to port 0, e.g. sock.bind(('', 0))
Directly use a desired port number in bind function, e.g. sock.bind(('', port_number))
We cannot get a free port number
Answer
Correct Answer:
Do not bind to a specific port, or bind to port 0, e.g. sock.bind(('', 0))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
325.
dWhat will be the output of following code? class Example: def __init__(self, i = 2, j = 3): self.i = i self.j = j def __str__(self): return"Example" def __eq__(self, other): return self.i * self.j == other.i * other.j def main(): x = Example(1, 2) y = Example(2, 1) print(x == y) main()
False
2
True
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
326.
Python programming language was designed by___ ?
Guid vano
Guido van Rossum
David
Centrum Wiskunde
Answer
Correct Answer:
Guido van Rossum
Note: This Question is unanswered, help us to find answer for this one
Check Answer
327.
Which of the following is floor division ?
%
&
//
#
Note: This Question is unanswered, help us to find answer for this one
Check Answer
328.
Which of the following code is valid to convert a buffer buf to JSON object?
A. buf.toJSON()
B. buf.json()
C. buf.covertToJson()
D. buf.jsonify()
Answer
Correct Answer:
A. buf.toJSON()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
329.
How to hide status bar in ios app with Swift?
We need to change info.plist file to hide status bar
We need override prefersStatusBarHidden() function on the view controller to return true
We need set UIApplication.sharedApplication().statusBarHidden=true; with viewWillAppear() function overriding
There is no way to hide it with swift, we need to combine Objective C functions
Answer
Correct Answer:
We need to change info.plist file to hide status bar We need override prefersStatusBarHidden() function on the view controller to return true We need set UIApplication.sharedApplication().statusBarHidden=true; with viewWillAppear() function overriding
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
330.
What are the states/features supported by a RLock object?
Locked
Owning thread
Recursion level
Unlocked
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
331.
Which of the following operator is overloaded by invert() ?
#
^
~
@
Note: This Question is unanswered, help us to find answer for this one
Check Answer
332.
Which of these is not a Python datatype?
int
float
long
decimal
Note: This Question is unanswered, help us to find answer for this one
Check Answer
333.
Which of the following data types is not supported in python ?
List
Generics
Numbers
Tuple
Note: This Question is unanswered, help us to find answer for this one
Check Answer
334.
If x = '10' (as a string), which of the following is the correct way to typecast it to an integer?
x = 10
makeint(x)
x.int()
int(x)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
335.
Which statement is true regarding the __all__ module level variable?
It is a list of strings defining all symbols in a module.
It is a dictionary defining all functions in a module.
It is a list of strings defining what symbols in a module will be exported when from import * is used on the module.
It is a dictionary defining what functions in a module will be exported when from import * is used on the module.
Answer
Correct Answer:
It is a dictionary defining what functions in a module will be exported when from import * is used on the module.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
336.
Which of the following statements are true regarding lists and arrays in Python?
Lists use more space than arrays.
Arrays can only hold homogeneous data.
Arrays can hold heterogeneous data, but it uses less memory.
Appending items to lists is slower than appending items to arrays.
Answer
Correct Answer:
Lists use more space than arrays. Arrays can only hold homogeneous data.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
337.
Which of the following statements is/are correct about range() and xrange()?
range() is faster when iterating over the same sequence multiple times.
xrange() is faster when iterating over the same sequence multiple times.
xrange() supports slices and list methods.
range() returns a list, while xrange() returns an xrange object.
Answer
Correct Answer:
range() is faster when iterating over the same sequence multiple times. range() returns a list, while xrange() returns an xrange object.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
338.
What is the best way to check if a list is empty? x = []
if not len(x):
if not x:
if x == []:
if len(x) == 0:
Answer
Correct Answer:
if not x:
Note: This Question is unanswered, help us to find answer for this one
Check Answer
339.
For the list "thelist = [1, 2, 3, 4, 5]", how could the last two elements of the list (4, 5) be selected using slices?
thelist[3:]
thelist[3,4]
thelist[3:4]
thelist[-2]
Answer
Correct Answer:
thelist[3:]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
340.
Which of the following code snippets can be used to get the multiples of 2 from the list a = [1, 2, 3, 4, 5, 6, 7, 8, 9] ?
b = filter(lambda x: x % 2 == 0, a)
b = [x for x in a if x % 2 == 0]
def filterfunc(x): return x % 2 == 0 b = filter(filterfunc, a)
All of these
Answer
Correct Answer:
All of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
341.
What function is used to find the absolute path of a file?
import os os.path.abspath("mydir/myfile.txt")
abspath("mydir/myfile.txt")
import os os.path.("mydir/myfile.txt")
import os ("mydir/myfile.txt").os.path.abspath
Answer
Correct Answer:
import os os.path.abspath("mydir/myfile.txt")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
342.
What is the correct way to open the file "test.txt" and append the text "foo" to it?
with open("test.txt", "r") as myfile: myfile.write("foo")
with open("test.txt", "w") as myfile: write("foo")
open("test.txt") as myfile: myfile.write("foo")
with open("test.txt", "a") as myfile: myfile.write("foo")
Answer
Correct Answer:
with open("test.txt", "a") as myfile: myfile.write("foo")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
343.
Which function prints all of the current properties and values of any kind of object?
dir(someObject)
someObject.__dict__
from pprint import pprint pprint (vars(someObject))
import inspect inspect.getobjectinfo(someObject)
Answer
Correct Answer:
from pprint import pprint pprint (vars(someObject))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
344.
To make numbers be of a specific length, zeroes are padded to the left. Which of the following is the best way to pad a string with zeroes to the left, to make its length 5? The string is: num = '123'
print num.zfill(3)
print 'd' % num
print num.zfill(5)
print 'd' % num
Answer
Correct Answer:
print num.zfill(5)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
345.
Which of the following is the proper way to declare custom exceptions in modern Python?
class MyException(Exception): pass
class MyException(): pass
class MyException(Error): pass
class MyException: pass
Answer
Correct Answer:
class MyException(Exception): pass
Note: This Question is unanswered, help us to find answer for this one
Check Answer
346.
Which of the following is the best way of checking if a string could be represented as a number?
def is_number(s): try: float(s) return True except ValueError: return False
import re check_regexp = re.compile("^\d*\.?\d*$")
def isNumber(token): for char in token: if not char in string.digits: return False return True
import re check_replace = lambda x: x.replace('.','',1).isdigit()
Answer
Correct Answer:
def is_number(s): try: float(s) return True except ValueError: return False
Note: This Question is unanswered, help us to find answer for this one
Check Answer
347.
Divide by zero is a very common error. Which of the following handles this exception?
DivideByZeroError
DivisionZeroError
ZeroDivisionError
DivisionError
Answer
Correct Answer:
ZeroDivisionError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
348.
Which of the following options is correct regarding the difference between __repr__ and __str__?
The goal of __repr__ is to be unambigous and __str__ is to be readable.
__repr__ and __str have no difference and are same everytime.
__repr__ prints the data the object holds and __str__ prints the name of object.
None of these.
Answer
Correct Answer:
The goal of __repr__ is to be unambigous and __str__ is to be readable.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
349.
Read the following code snippet: >>> o1 = C() >>> o1.lst = [1,2,3] >>> o3 = copy.deepcopy(o1) >>> o1.lst.append(17) What will be the output of '>>> o3.lst' and '>>> o1.lst'?
[1, 2, 3] and [1, 2, 3, 17]
[1, 2, 3, 17] and [1, 2, 3, 17]
[1, 2, 3] and [1, 2, 3]
None of these
Answer
Correct Answer:
[1, 2, 3] and [1, 2, 3, 17]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
350.
Read the following statements: Statement 1: By default, a print statement adds a linefeed to the end of its output. Statement 2: The linefeed can be eliminated by adding a trailing comma to the statement. Which of the following is correct?
Statement 1 is true, but statement 2 is false.
Statement 1 is false, but statement 2 is true.
Both statements are true.
Both statements are false.
Answer
Correct Answer:
Both statements are true.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
351.
Which of the following will close a list in Python?
new_list = old_list[:]
new_list = list(old_list)
import copy
new_list = copy.copy(old_list)
import copy
new_list = copy.deepcopy(old_list)
Answer
Correct Answer:
new_list = old_list[:] new_list = list(old_list) import copy
new_list = copy.copy(old_list) import copy
new_list = copy.deepcopy(old_list)
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
352.
Which of the following statements about the 'has_key()' dictionary method and the 'in' operator are true? d = {'a': 1, 'b': 2} 'a' in d d.has_key('a')
The 'in' operator follows the PEP (Python Enhancement Proposals) recommendations more.
The 'has_key()' dictionary method follows the PEP (Python Enhancement Proposals) recommendations more.
'in' has better performance.
'has_key()' has better performance
Answer
Correct Answer:
The 'in' operator follows the PEP (Python Enhancement Proposals) recommendations more. 'in' has better performance.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
353.
Which of the following statements are correct?
'str' 'ing'
'str'.strip() + 'ing'
'str'.strip() 'ing'
'str' + 'ing'
Answer
Correct Answer:
'str' 'ing' 'str'.strip() + 'ing' 'str' + 'ing'
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
354.
Which of the following is the correct way to get the size of a list in Python?
list.length()
len(list)
sizeof(list)
list.size()
Answer
Correct Answer:
len(list)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
355.
Which of the following code snippets would work as the best switch-case equivalent?
def switch(x): return { 'a': 1, 'b': 2, }[x]
case_dict = { 'a': 1, 'b': 2, } def switch(x): return case_dict[x]
case_dict = { 'a': 1, 'b': 2, } def switch(x): return case_dict.get(x, 0)
case_dict = { 'a': 1, 'b': 2, } def switch(x): return case_dict[x], 0
Answer
Correct Answer:
case_dict = { 'a': 1, 'b': 2, } def switch(x): return case_dict.get(x, 0)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
356.
Read the following statements:
Statement 1: The new-style class int already supports Bitwise, so there is no need to implement it again in derived classes.
Statement 2: With new-style classes, data values can be referred to directly with ‘myself’.
Which of the following is correct?
Statement 1 is true, but statement 2 is false.
Statement 2 is true, but statement 1 is false.
Both statement are true.
Both statement are false.
Answer
Correct Answer:
Statement 1 is true, but statement 2 is false.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
357.
Which of the following types is correct for instances of user-defined classes?
Types.Instance
Types, insType
Types.InstanceType
Types.TypeInstance
Answer
Correct Answer:
Types.InstanceType
Note: This Question is unanswered, help us to find answer for this one
Check Answer
358.
Python 2.3+ includes a standard module that implements a set datatype. Which of the following statements is true about the set datatype?
A set is an unordered collection of hashable objects.
No object can occur in a set more than once.
A set resembles a dict that has only keys but no values.
Sets utilize bitwise and Boolean syntax to perform basic set-theoretic operations.
All of these.
Answer
Correct Answer:
All of these.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
359.
Which of the following is the correct way to print to stderr in Python?
sys.stderr.write('my_error')
print >> sys.stderr, 'my_error'
from __future__ import print_function print('my_error', file=sys.stderr)
All of these
Answer
Correct Answer:
All of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
360.
Function sys.getrefcount(obj) returns the number of references to the object obj. Which of the following is the correct value returned by this function?
The total number of references
One higher than the total number of references
One lesser than the total number of references
Double of the total number of references
Answer
Correct Answer:
One higher than the total number of references
Note: This Question is unanswered, help us to find answer for this one
Check Answer
361.
What is the difference between the two methods, "foo is None", and "foo == None", for the purposes of determining if the type of an object is None?
"is" always returns True if it compares the same object instance whereas the value returned by "==" is determined by the __eq__() method.
"==" always returns True if it compares the same object instance whereas the value returned by "is" is determined by the __eq__() method.
There is no difference between the two, but "==" is preferred by convention.
There is no difference between the two, but "is" is preferred by convention.
Answer
Correct Answer:
"is" always returns True if it compares the same object instance whereas the value returned by "==" is determined by the __eq__() method.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
362.
Which of the following is the correct way to output the name of any function (including builtin functions) using Python?
theFunction.func_name
theFunction.__name__
theFunction.name()
theFunction.__func_name__
Answer
Correct Answer:
theFunction.__name__
Note: This Question is unanswered, help us to find answer for this one
Check Answer
363.
Which of the following is correct about Python?
Python is a byte-code compiled programming language.
Python uses a virtual machine to run machine-abstracted instructions.
Python is an object-oriented language.
Python is a declarative programming language.
All of these.
Answer
Correct Answer:
Python is a byte-code compiled programming language. Python uses a virtual machine to run machine-abstracted instructions.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
364.
Read the following statements in which nested filters are used: shortline = lambda line: len(line) < 25 short_regvals = filter(shortline, (isRegDBVal, lines)) Which of the following errors is present in the above code?
Nested filters are not allowed.
The filter function is missing for (isRegDBval, lines).
The function shortline should be in a bracket-like filter(shortline), (isregDBval), lines).
None of these
Answer
Correct Answer:
The filter function is missing for (isRegDBval, lines).
Note: This Question is unanswered, help us to find answer for this one
Check Answer
365.
Which of the following modules can be used for profiling Python code?
profile
cProfile
pyProfile
profile and cProfile
Answer
Correct Answer:
profile and cProfile
Note: This Question is unanswered, help us to find answer for this one
Check Answer
366.
Consider the following code: myString = ' Hello! ' Which of the following choices will remove the spaces at the beginning and end of myString?
myString.strip()
myString.trim()
myString.replace(' ','')
myString.lstrip()
Answer
Correct Answer:
myString.strip()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
367.
While running an application, a user pressed the interrupt key (Ctrl + C). Which of the following exceptions will occur?
InterruptError
KeyboardInterrupt
KeyboardInterruptError
None of these
Answer
Correct Answer:
KeyboardInterrupt
Note: This Question is unanswered, help us to find answer for this one
Check Answer
368.
What is the output of the following code? class A(object): def __init__(self): print "Constructor A was called" class B(A): def __init__(self): print "Constructor B was called" class C(B): def __init__(self): super(C,self).__init__() print "Constructor C was called" class D(C): def __init__(self): super(D,self).__init__() print "Constructor D was called" d = D()
Constructor D was called
Constructor A was called Constructor B was called Constructor C was called Constructor D was called
Constructor B was called Constructor C was called Constructor D was called
Constructor B was called
Answer
Correct Answer:
Constructor B was called Constructor C was called Constructor D was called
Note: This Question is unanswered, help us to find answer for this one
Check Answer
369.
What is the correct syntax that will set the variable "var1" to the value "correct" if variable "a" is greater than 1?
var1 = "correct" if a > 1
var1 = "correct" if a > 1 else None
var1 = "correct" if a > 1 else if None
var1 = "correct" if a > 1 else
Answer
Correct Answer:
var1 = "correct" if a > 1 else None
Note: This Question is unanswered, help us to find answer for this one
Check Answer
370.
Which of the following are correct ways to test if a key exists in a dictionary?
if dict.get(key) is not None: do something
if key in dict: do something
if dict.haskey(key) is not None: do something
if dict.getkey(key) is not None: do something
Answer
Correct Answer:
if dict.get(key) is not None: do something if key in dict: do something
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
371.
Which of the following will determine the number of CPUs available in the operating environment?
import os os..cpu_count()
import sys sys..cpu_count()
import psutil psutil.NUM_CPUS
import multiprocessing multiprocessing.cpu_count()
Answer
Correct Answer:
import psutil psutil.NUM_CPUS import multiprocessing multiprocessing.cpu_count()
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
372.
Which of the following is the correct way to recursively find files with the extension ".html" in the directory "site" with Python?
import fnmatch import os matches = os.walk('site', '*.html')
import fnmatch import os matches = [] for root, dirnames, filenames in os.walk('site'): for filename in fnmatch(filenames, '*.html'): matches(os.path.join(root, filename))
import fnmatch import os matches = [] for root, dirnames, filenames in os.walk('site'): for filename in fnmatch.filter(filenames, '*.html'): matches.append(os.path.join(root, filename))
matches = [] for root, dirnames, filenames in os.walk('site'): for filename in fnmatch.filter(filenames, '*.html'): matches.append(os.path.join(root, filename))
Answer
Correct Answer:
import fnmatch import os matches = [] for root, dirnames, filenames in os.walk('site'): for filename in fnmatch.filter(filenames, '*.html'): matches.append(os.path.join(root, filename))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
373.
Read the following code: def approx(x): if hasattr(x,'__and__'): return x & ~0x0FL try: return (round(x.real,2)+round(x.imag,2)*1j) exception AttributeError: return round(x,2) Which of the following lines is incorrect in the above code?
def approx(x):
__and__
round(x.real,2)+round(x.imag,2)*1j
exception AttributeError:
None of these
Answer
Correct Answer:
exception AttributeError:
Note: This Question is unanswered, help us to find answer for this one
Check Answer
374.
Given a program that has different combinations of conditions, programming a custom function for each combined condition can produce an excessive number of functions. Instead, for conditions that should be jointly satisfied, several filters can be nested within each other. Which of the following statements does this correctly?
short_regvals = filter(shortline,(isRegDBVal, lines))
short_regvals = filter(filter(isRegDBVal, lines),shortline)
short_regvals = filter(shortline, filter(isRegDBVal, lines))
None of these
Answer
Correct Answer:
short_regvals = filter(shortline, filter(isRegDBVal, lines))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
375.
Which of the following code samples will read arguments if the script is run from the command line?
import argparse parser = argparse.ArgumentParser() print parser.arguments()
from optparse import OptionParser parser = OptionParser() print parser.arguments()
import sys print sys.argv
import os print os.argv
Answer
Correct Answer:
import sys print sys.argv
Note: This Question is unanswered, help us to find answer for this one
Check Answer
376.
Select all incorrect statements regarding functions decorated with staticmethod and functions decorated with classmethod:
A classmethod receives the class as its implicit first argument whereas a staticmethod does not receive an implicit first argument.
Syntax to declare a classmethod: class C: @classmethod def f(cls, arg1, arg2, ...): ...
Syntax to declare a staticmethod: class C: @staticmethod def f(arg1, arg2, ...): ...
The first argument for a classmethod function must always be class.
Staticmethod is callable without instantiating the class first, whereas classmethod is not.
Answer
Correct Answer:
A classmethod receives the class as its implicit first argument whereas a staticmethod does not receive an implicit first argument. Syntax to declare a classmethod: class C: @classmethod def f(cls, arg1, arg2, ...): ... Syntax to declare a staticmethod: class C: @staticmethod def f(arg1, arg2, ...): ... The first argument for a classmethod function must always be class.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
377.
Given the two dictionaries 'x' and 'y', which of these codes would not create a final, merged dictionary 'z'? x = {'a':1, 'b': 2} y = {'b':10, 'c': 11} z = {'a': 1, 'c': 11, 'b': 10}
z = dict(x.items() + y.items())
z = x.copy() z.update(y)
z = dict(x, **y)
z = x.update(y)
z = dict(list(x.items()) + list(y.items()))
Answer
Correct Answer:
z = x.update(y)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
378.
If a name has not been bound inside some accessible scope, how can it be dereferenced?
Through a global namespace
Through package.module
Through the normal dereference process
It cannot be dereferenced
Answer
Correct Answer:
It cannot be dereferenced
Note: This Question is unanswered, help us to find answer for this one
Check Answer
379.
What will be the output of the following statement: >>> "ab123".islower(), '123'.islower(), 'Ab123'.islower()
(True,True,False)
(True,False,True)
(True,False,False)
(False,False,False)
Answer
Correct Answer:
(True,False,False)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
380.
Which of the following is an incorrect way of determining whether the type of an object (obj) is list?
type(obj) == list
type(obj) is list
isinstance(obj, list)
obj is list
Answer
Correct Answer:
isinstance(obj, list)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
381.
Read the following code snippet: import types, exceptions def overloaded_get_text(o): if type(o) is type.FileType: text = o.read() else: raise exceptions.TypeError return text Which of the following lines has incorrect syntax?
if type(o) is type.FileType:
text = o.read()
raise exceptions.TypeError
None of these
Answer
Correct Answer:
if type(o) is type.FileType:
Note: This Question is unanswered, help us to find answer for this one
Check Answer
382.
Which option will import a module which is not in PYTHONPATH or the current directory?
import <modulename>
Add the path in program by sys.path.insert(<path>)
<modulename> import *
Put __init__.py file in the module path and import it using the import statement
Answer
Correct Answer:
Add the path in program by sys.path.insert(<path>)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
383.
Which of the following system attributes keeps the integer of the largest supported code point for a Unicode character under the current configuration?
sys.maxint
sys.maxunicode
sys.maxcode
sys.maxnumber
Answer
Correct Answer:
sys.maxunicode
Note: This Question is unanswered, help us to find answer for this one
Check Answer
384.
Which of the following code samples will determine the last day of a given month?
import datetime datetime.date(year, month, day).replace(day=1,month=datetime.date(year, month, day).month+1)-timedelta(days=1)
import calendar calendar.monthrange(year, month)[1]
import datetime dt = datetime.date(year, month, day) next_month = (dt.month % 12) + 1 end_date = datetime.date(dt.year, next_month, 1) - datetime.timedelta(days=1) return end_date
import calendar calendar.lastday(year, month)
Answer
Correct Answer:
import datetime dt = datetime.date(year, month, day) next_month = (dt.month % 12) + 1 end_date = datetime.date(dt.year, next_month, 1) - datetime.timedelta(days=1) return end_date
Note: This Question is unanswered, help us to find answer for this one
Check Answer
385.
Read the following statements: >>> word = 'Help' + 'A' >>> word[2:] Which of the following will be the output of the above code?
lpA
He
pA
lp
Note: This Question is unanswered, help us to find answer for this one
Check Answer
386.
Which of the following statements will redirect the output of the print statement into a file-like object named 'test'?
print >> open('test','w'), "Pi: %.3f" % 3.1415, 27+11
print 'test', "Pi: %.3f" % 3.1415, 27+11
print open('test','w'), "Pi: %.3f" % 3.1415, 27+11
print $$ open('test','w'), "Pi: %.3f" % 3.1415, 27+11
Answer
Correct Answer:
print >> open('test','w'), "Pi: %.3f" % 3.1415, 27+11
Note: This Question is unanswered, help us to find answer for this one
Check Answer
387.
Which of the following exceptions is raised while using sys.exit()?
SysExit
SystemExit
Exit
ExceptExit
Answer
Correct Answer:
SystemExit
Note: This Question is unanswered, help us to find answer for this one
Check Answer
388.
What is the best way to randomly select an item from list?
foo = ['a', 'b', 'c', 'd', 'e'] from random import choice print choice(foo)
foo = ['a', 'b', 'c', 'd', 'e'] from random import randrange random_index = randrange(0,len(foo)) print foo[random_index]
foo = ['a', 'b', 'c', 'd', 'e'] import random print int(random.random() * len(foo))
foo = ['a', 'b', 'c', 'd', 'e'] import random print foo[int(random.random() * len(foo)+1)]
Answer
Correct Answer:
foo = ['a', 'b', 'c', 'd', 'e'] from random import choice print choice(foo)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
389.
What would be the output of the following code? def change_list(list1, list2): list1.append('four') list2 = ['and', 'we', 'can', 'not', 'lie'] outer_list1 = ['one', 'two', 'three'] outer_list2 = ['we', 'like', 'proper', 'English'] change_list(outer_list1, outer_list2) print outer_list1 print outer_list2
['one', 'two', 'three', 'four'] ['we', 'like', 'proper', 'English']
['one', 'two', 'three', 'four'] ['and', 'we', 'can', 'not', 'lie']
['one', 'two', 'three'] ['we', 'like', 'proper', 'English']
['one', 'two', 'three'] ['and', 'we', 'can', 'not', 'lie']
Answer
Correct Answer:
['one', 'two', 'three', 'four'] ['we', 'like', 'proper', 'English']
Note: This Question is unanswered, help us to find answer for this one
Check Answer
390.
Which of the following code snippets converts the hexademical number 0x1000 to a decimal correctly?
int('1000', 16
int(1000)
1 * (16 ** 4) + 0 + 0 + 0
int.fromhex('0x1000')
Answer
Correct Answer:
int('1000', 16
Note: This Question is unanswered, help us to find answer for this one
Check Answer
391.
Sometimes, an object needs to be converted into its string representation. Fortunately, the object class provides functionality for this. Which of the following returns a string representation of the object 'self'?
object.__repr__(self)
object.__string__(self)
object.__conv__(self)
object.__slz__(self)
Answer
Correct Answer:
object.__repr__(self)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
392.
Which of the following code snippets concatenates the list a_list = [1, 2, 3] with the tuple a_tuple = (4, 5), so the result would be [1, 2, 3, 4, 5]?
a_list + a_tuple
a_list.extend(a_tuple)
a_list.append(a_tuple)
a_list.append(*a_tuple)
Answer
Correct Answer:
a_list.extend(a_tuple)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
393.
Which of the following is the correct way to write a generator which will output the numbers between 1 and 100 (inclusive)?
def onehundred(start, end): current = start while current <= end: yield current current += 1 for x in onehundred(1, 100): print x
def onehundred(start, end): current = start while current <= end: return current current += 1 for x in onehundred(1, 100): print x
def onehundred(start, end): current = start while current <= end: yield current current += 2 for x in onehundred(1, 100): print x
def onehundred(start, end): while current <= end: yield current current += 1 for x in onehundred(1, 100): print x
Answer
Correct Answer:
def onehundred(start, end): current = start while current <= end: yield current current += 1 for x in onehundred(1, 100): print x
Note: This Question is unanswered, help us to find answer for this one
Check Answer
394.
What is the correct way to delete a directory that is not empty using Python?
os.remove('/directory')
os.rmtree('/directory')
shutil.rmtree('/directory')
import shutil shutil.rmtree('/directory')
Answer
Correct Answer:
import shutil shutil.rmtree('/directory')
Note: This Question is unanswered, help us to find answer for this one
Check Answer
395.
Which of the following is the correct way to execute a program from inside Python without having to consider how the arguments/quotes are formatted?
import subprocess subprocess.call('C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt')
os.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
import subprocess subprocess.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
subprocess.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
Answer
Correct Answer:
import subprocess subprocess.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
396.
What is the output of the following code?
def foo(param1, *param2):
print param1
print param2
def bar(param1, **param2):
print param1
print param2
foo(1,2,3,4,5)
bar(1,a=2,b=3)
TypeError: foo() got multiple values for keyword argument 'param1'
1 (2, 3, 4, 5) 1 (2, 3)
1 (2, 3, 4, 5) 1 {'a': 2, 'b': 3}
1 {2, 3, 4, 5} 1 ('a': 2, 'b': 3)
Answer
Correct Answer:
1 (2, 3, 4, 5) 1 {'a': 2, 'b': 3}
Note: This Question is unanswered, help us to find answer for this one
Check Answer
397.
Which of the following is the correct way to call the private method, myPrivateMethod(), in class MyClass, using dir(obj)?
class MyClass:
def __myPrivateMethod(self):
print "Private Method"
obj = MyClass()
print dir(obj)
__myPrivateMethod
_MyClass__myPrivateMethod
myPrivateMethod
A private method will not be shown in the output.
Answer
Correct Answer:
_MyClass__myPrivateMethod
Note: This Question is unanswered, help us to find answer for this one
Check Answer
398.
What is a metaclass in Python?
A class that is inherited from
A class that inherits from another class
Something that can be attached to any class, that gives it a constant set of attributes
Something that creates "class" objects
Answer
Correct Answer:
Something that can be attached to any class, that gives it a constant set of attributes
Note: This Question is unanswered, help us to find answer for this one
Check Answer
399.
What is the output of the following code:
name = 'Jon'
name.rjust(4, 'A')
'Jon A'
'A Jon'
'AJon'
'JonA'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
400.
Which of the following methods returns the ASCII value of a character in Python?
ascii
ord
asciicode
None of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
401.
Which of the following is the base class for new-style file objects?
base
file
fileobject
filebase
Note: This Question is unanswered, help us to find answer for this one
Check Answer
402.
Which of the following is the correct way to check to see if the variable theVar is an integer?
isinstance(theVar, int)
theVar.isinstance(int)
int.isinstance(theVar)
is(theVar, int)
Answer
Correct Answer:
isinstance(theVar, int)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
403.
How can an element be removed from a list using its list index?
myList.remove(index)
pop myList[index]
del myList[index]
myList.delete(index)
Answer
Correct Answer:
del myList[index]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
404.
Which of the following statements are true?
A. ._variable is semi-private and meant just for convention.
B. .__variable is considered superprivate and gets name mangled to prevent accidental access.
C. .__variable__ is typically reserved for built-in methods or variables.
A
B
C
A, B, and C
Answer
Correct Answer:
A, B, and C
Note: This Question is unanswered, help us to find answer for this one
Check Answer
405.
Which Python module can be used for copying files?
util
shutil
copy
filecopy
Note: This Question is unanswered, help us to find answer for this one
Check Answer
406.
Which of the following functions modifies the list in place to indicate which items are directories, and which are plain files?
dircache.listdir(path, lst)
dircache.annotate(path, lst)
dircache.filter(path, lst)
dircache.scan(path, lst)
Answer
Correct Answer:
dircache.annotate(path, lst)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
407.
Which of the following will throw an exception in Python?
call Exception("Here is an Exception!")
throw Exception("Here is an Exception!")
raise Exception("Here is an Exception!")
create Exception("Here is an Exception!")
Answer
Correct Answer:
raise Exception("Here is an Exception!")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
408.
In Python 2.x, which of the following is the way to check to make sure that the variable 'x' is not a string?
assert isinstance(x, basestring)
assert not isinstance(x, basestring)
assert not instance(x, basestring)
assert not x.isinstance(basestring)
Answer
Correct Answer:
assert not isinstance(x, basestring)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
409.
Which of the following is the correct way to flush output of Python print?
import sys sys.stdout.flush()
class flushfile(file): def __init__(self, f): self.f = f def write(self, x) self.f.write(x) self.f.flush() import sys sys.stdout = flushfile(sys.stdout)
import sys sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
Running python with the -u command-line switch
Answer
Correct Answer:
import sys sys.stdout.flush()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
410.
Which list flattening method will have the shortest running time?
l = [ [1, 2, 3], [4, 5, 6], [7], [8, 9] ] * 99 import itertools list( itertools.chain.from_iterable( l ) )
l = [ [1, 2, 3], [4, 5, 6], [7], [8, 9] ] * 99 reduce( lambda x, y: x + y, l )
l = [ [1, 2, 3], [4, 5, 6], [7], [8, 9] ] * 99 sum( l, [ ] )
l = [ [1, 2, 3], [4, 5, 6], [7], [8, 9] ] * 99 [ item for sublist in l for item in sublist ]
Answer
Correct Answer:
l = [ [1, 2, 3], [4, 5, 6], [7], [8, 9] ] * 99 import itertools list( itertools.chain.from_iterable( l ) )
Note: This Question is unanswered, help us to find answer for this one
Check Answer
411.
Which of the following is the correct method for changing a global variable inside a function?
def change_globvar(): globvar = 1
def change_globvar(): global globvar globvar = 1
def change_globvar(): import globvar globvar = 1
def change_globvar(): global globvar = 1
Answer
Correct Answer:
def change_globvar(): global globvar globvar = 1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
412.
What is the most flexible way to call the external command "ls -l" in Python?
from subprocess import call call(["ls", "-l"])
from subprocess import call call("ls -l")
os.system("ls -l")
os.system(["ls"], ["-l"])
Answer
Correct Answer:
from subprocess import call call(["ls", "-l"])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
413.
What is the result of the following code:
>>> import itertools
>>> x = itertools.count(0)
>>> x.__class__.__name__
Nothing
'count'
'Object'
'None'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
414.
Which of the following is the best way to reverse the string 'Test String' in Python?
string.reverse('Test String')
'Test String'[::-1]
reversed('Test String')
'Test String'[-1:0]
Answer
Correct Answer:
'Test String'[::-1]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
415.
Writing to STDOUT and STDERR is fairly inflexible, and most of the time the print statement accomplishes the same purpose more flexibly. How many arguments can a print statement handle?
1
2
7
Any number
Answer
Correct Answer:
Any number
Note: This Question is unanswered, help us to find answer for this one
Check Answer
416.
How can a list be split into equal sized chunks?
f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc
def chunks(l, n): for i in xrange(0, len(l), n): yield l[i:i+n]
def split_seq(seq, num_pieces): start = 0 for i in xrange(num_pieces): stop = start + len(seq[i::num_pieces]) yield seq[start:stop] start = stop
chunks = lambda l, n: [l[x: x+n] for x in xrange(0, len(l), n)] chunks(l, 10)
Answer
Correct Answer:
def chunks(l, n): for i in xrange(0, len(l), n): yield l[i:i+n]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
417.
Inheriting from a base class enables a custom class to use a few new capabilities, such as slots and properties. Which of the following is the base class of new-style datatypes?
base
object
dict
custom
None of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
418.
What would the 'sorted_tel' be in the following code:
tel = {'jack': 4098, 'sape': 5139, 'bill': 3678, 'mike': 2122}
sorted_tel = sorted(tel.items(), key=lambda x: x[1])
A dictionary sorted by the second element.
A list of Tuples sorted by the second element.
A list of dictionaries sorted by the first element.
A dictionary sorted by the first element.
A list of Tuples sorted by the first element.
Answer
Correct Answer:
A list of Tuples sorted by the second element.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
419.
Read the following statements:
Statement 1: Many string module functions are now also available as string object methods.
Statement 2: To use string object methods, there is no need to import the string module.
Which of the following is correct?
Statement 1 is true, but statement 2 is false.
Statement 2 is true, but statement 1 is false.
Both statements are true.
Both statements are false.
Answer
Correct Answer:
Both statements are true.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
420.
Read the following statements:
>>> import string
>>> s = 'mary\011had a little lamb'
>>> print s
Which of the following will be the output of the above code snippet?
mary had a little lamb
mary\011 had a little lamb
mary had a little lamb
mary\011had a little lamb
Answer
Correct Answer:
mary had a little lamb
Note: This Question is unanswered, help us to find answer for this one
Check Answer
421.
Read the following statements:
>>> lst = ['spam','and','eggs']
>>> lst[2] = 'toast'
>>> print ''.join(lst)
>>> print ' '.join(lst)
Which of the following is the output of the second print statement in the above code snippet?
spam and eggs
spamandeggs
spamandtoast
spam and toast
Answer
Correct Answer:
spam and toast
Note: This Question is unanswered, help us to find answer for this one
Check Answer
422.
Given a program that saved a text file in the directory "/temp_files", which of the following will make sure that "/temp_files" exists before writing the file?
d = os.path.dirname("/temp_files") if not os.path.exists(d): os.makedirs(d)
d = os.path("/temp_files") if not os.path(d): os.makedirs(d)
d = os.path.dirname("/temp_files") if os.path.exists(d): os.makedirs(d)
if not os.path.exists("/temp_files"): os.makedirs(d)
Answer
Correct Answer:
if not os.path.exists("/temp_files"): os.makedirs(d)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
423.
In Python, built-in exceptions can be inherited from. Which of the following is the base exception class?
Exceptions
BaseException
Exception
Except
Answer
Correct Answer:
Exception
Note: This Question is unanswered, help us to find answer for this one
Check Answer
424.
What is the best way to check if the object 'myobject' is iterable in Python?
myobject.isIter()
try: [ e for e in myobject] except TypeError: print myobject, 'is not iterable'
try: iter.myobject except: print myobject, 'is not iterable'
if [ e for e in myobject]: print myobject, 'is iterable' else: print myobject, 'is not iterable'
Answer
Correct Answer:
try: [ e for e in myobject] except TypeError: print myobject, 'is not iterable'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
425.
When is the "yield" keyword used in Python?
When other processes need to take precedence over the Python script
To break out of a loop
When a function needs to return a list that only needs to be read through once
Never
Answer
Correct Answer:
When a function needs to return a list that only needs to be read through once
Note: This Question is unanswered, help us to find answer for this one
Check Answer
426.
How many arguments can a print statement handle?
One
Any number of string arguments only
Any number of numeric arguments only
Any number of string or numeric arguments
Answer
Correct Answer:
Any number of string or numeric arguments
Note: This Question is unanswered, help us to find answer for this one
Check Answer
427.
Which of the following options are true regarding these two code samples?
Code sample 1:
def main():
for i in xrange(10**8):
pass
main()
Code sample 2:
for i in xrange(10**8):
pass
Code sample 2 would take a longer time to complete than code sample 1. This is because in code sample 1, 'i' is local, whereas in code sample 2 it is global.
Code sample 1 would take a longer time to complete than code sample 2. This is because code sample 1 would take additional time in defining and calling the function.
Code sample 2 would take less time to complete because Python is able to detect pass as a null operation, and skip the whole loop.
None of these.
Answer
Correct Answer:
Code sample 2 would take a longer time to complete than code sample 1. This is because in code sample 1, 'i' is local, whereas in code sample 2 it is global.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
428.
The least sophisticated form of text output in Python is writing to open files. In particular, which of the following streams can be used?
STDOUT
STDERR
STDPRN
STDFIL
Note: This Question is unanswered, help us to find answer for this one
Check Answer
429.
Which of the following statements can be used to remove an item from a list by giving the index?
remove listname[index]
del listname[index
kill listname[index]
None of these
Answer
Correct Answer:
del listname[index
Note: This Question is unanswered, help us to find answer for this one
Check Answer
430.
Which of the following exceptions occurs while importing a module?
ModuleError
ImportError
ImportModuleError
ReferenceError
Answer
Correct Answer:
ImportError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
431.
Which is not used to install Python packages?
easy_install
pip
distribute
installtools
Answer
Correct Answer:
installtools
Note: This Question is unanswered, help us to find answer for this one
Check Answer
432.
Which of the following commands would produce the following result:
result: 'line 1\nline 2'
result = '\nline 1\nline 2\n'.rstrip()
result = '\nline 1\nline 2\n'.split()
result = '\nline 1\nline 2\n'.strip()
result = '\nline 1\nline 2\n'.lstrip()
result = '\nline 1\nline 2\n'.splitlines()
Answer
Correct Answer:
result = '\nline 1\nline 2\n'.strip()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
433.
Read the following statements:
Statement 1: A simple assignment statement binds a name into the current namespace, unless that name has been declared as global.
Statement 2: A name declared as global is bound to the global (module-level) namespace.
Which of the following is correct?
Statement 1 is true, but statement 2 is false.
Statement 2 is true, but statement 1 is false.
Both statements are true.
Both statements are false.
Answer
Correct Answer:
Both statements are true.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
434.
Which of the following functions is used to send audio data via the Internet?
email.MIMEAudio(audiodata [,subtype [,encoder [,**params]]])
email.SendAudio(audiodata [,subtype [,encoder [,**params]]])
email.MIMEAudio.MIMEAudio(audiodata [,subtype [,encoder [,**params]]])
email.MIMEAudio.SendAudio(audiodata [,subtype [,encoder [,**params]]])
Answer
Correct Answer:
email.MIMEAudio.MIMEAudio(audiodata [,subtype [,encoder [,**params]]])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
435.
Which of the following statements copy the contents of a list and not just a reference to the list?
newlist = oldlist
newlist = oldlist[:]
newlist = oldlist(dummy)
None of these
Answer
Correct Answer:
newlist = oldlist[:]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
436.
Which of the following modules is used internally to determine whether a path matches?
dircmp
filecompare
fncmp
fnmatch
Note: This Question is unanswered, help us to find answer for this one
Check Answer
437.
Which of the following modules keep prior directory listings in the memory to avoid the need for a new call to the file system?
sys
FileSys
dirsys
dircache
Note: This Question is unanswered, help us to find answer for this one
Check Answer
438.
Consider the function:
def hello():
return "Hello, world!"
Which of the following is the correct way to make a decorator that could be used to make hello() return "#Hello, world!#"?
def hello(): return "#Hello, world!#"
def hashes(fn): def wrapped(): return "#" + fn() + "#" return wrapped @hashes def hello(): return "Hello, world!"
def hashes(fn): def wrapped(): return "#" + "#" return wrapped @hashes def hello(): return "Hello, world!"
def hashes(fn): def wrapped(): print "#" + fn() + "#" return @hashes def hello(): return "Hello, world!"
Answer
Correct Answer:
def hashes(fn): def wrapped(): return "#" + "#" return wrapped @hashes def hello(): return "Hello, world!"
Note: This Question is unanswered, help us to find answer for this one
Check Answer
439.
The most important element of the email package is the message. The email class provides the classes for messages in Python. Which of the following classes is used for the message?
email.Message
email.message.Message
email.messages
email.emailmessage
Answer
Correct Answer:
email.message.Message
Note: This Question is unanswered, help us to find answer for this one
Check Answer
440.
One common way to test a capability in Python is to try to do something, and catch any exceptions that occur.
Which of the following is the correct mechanism of trapping an error?
try: code to be verified will come here exception <except>:
try: code to be verified will come here except <exception>:
try: code to be verified will come here exception:
try: code to be verified will come here exception <exception>:
Answer
Correct Answer:
try: code to be verified will come here except <exception>:
Note: This Question is unanswered, help us to find answer for this one
Check Answer
441.
Which is the correct way to remove an installed Python package?
easy_install -v <package>
pip uninstall <package>
easy_install -u <package>
pip -m <package>
Answer
Correct Answer:
pip uninstall <package>
Note: This Question is unanswered, help us to find answer for this one
Check Answer
442.
Which of the following statements imports every name in a module namespace into the current namespace?
from modname import All
from modname import *
from modname import ?
from modname import All as *
Answer
Correct Answer:
from modname import *
Note: This Question is unanswered, help us to find answer for this one
Check Answer
443.
Which of the following protocol libraries can be used for an email implementation in a Python application?
telnetlib
smtplib
ftplib
None of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
444.
Which user input method will act like a file-object on which read and readline functions can be called?
sys.stdin
raw_input()
input()
sys.argv
Answer
Correct Answer:
sys.stdin
Note: This Question is unanswered, help us to find answer for this one
Check Answer
445.
The core text processing tasks in working with email are parsing, modifying, and creating the actual messages. Which of the following modules deal with parsing and processing email messages?
MimeWriter
mimify
Both MimeWriter and mimify
Neither MimeWriter nor mimify
Answer
Correct Answer:
Both MimeWriter and mimify
Note: This Question is unanswered, help us to find answer for this one
Check Answer
446.
Which function could be used to list every file and folder in the current directory?
os.dirnames('.')
os.listdir('.')
os.listdir('/')
os.ls()
Answer
Correct Answer:
os.listdir('.')
Note: This Question is unanswered, help us to find answer for this one
Check Answer
447.
Which of the following modules lets you check whether two files are identical, and whether two directories contain some identical files?
dircomp
filecompare
filecmp
structcomp
Note: This Question is unanswered, help us to find answer for this one
Check Answer
448.
How can a null object be declared in Python?
none
None
null
Null
Note: This Question is unanswered, help us to find answer for this one
Check Answer
449.
It is possible to use encoding other than ASCII in Python source files. The best way to do it is to put one more special comment line right after the #! line to define the source file encoding. Which of the following is the correct statement to define encoding?
coding: iso-8859-15
# -*- iso-8859-15 -*-
# -*- coding: iso-8859-15 -*-
None of these
Answer
Correct Answer:
# -*- coding: iso-8859-15 -*-
Note: This Question is unanswered, help us to find answer for this one
Check Answer
450.
Which of the following is the correct prototype of the string.find() function?
string.find(s, sub ,start ,end)
string.find(s, sub ,start [,end])
string.find(s, sub [,start [,end]])
string.find(s, sub [,start] ,end)
Answer
Correct Answer:
string.find(s, sub [,start [,end]])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
451.
Which of the following variables store parameters passed from outside?
sys.param
sys.arg
sys.argv
sys.prm
Note: This Question is unanswered, help us to find answer for this one
Check Answer
452.
Which of the following are the main features of Python?
Cross-platform
Extensible
Object-oriented, with multiple inheritance
Written in Java
Overloading of common operators
All of these
Answer
Correct Answer:
Cross-platform
Note: This Question is unanswered, help us to find answer for this one
Check Answer
453.
Various email and news clients store messages in a variety of formats, many providing hierarchical and structured folders. Which of the following provides a uniform API for reading the messages stored in all the most popular folder formats?
mailstruct
emailarch
emailfolders
mailbox
Note: This Question is unanswered, help us to find answer for this one
Check Answer
454.
Object is the base class of new-style datatypes. Which of the following functions is not a member of the object class?
object.__eq__(self, other)
object.__ne__(self, other)
object.__nz__(self)
object.__repr__(self)
None of these
Answer
Correct Answer:
object.__nz__(self)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
455.
Which of the following members of the object class compare two parameters?
object.__eq__(self, other)
object.__ne__(self, other)
object.__compare__(self, other)
object.__equals__(self, other)
object.__co__(self, other)
None of these
Answer
Correct Answer:
object.__eq__(self, other) object.__ne__(self, other)
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
456.
Which of the following will disable output buffering in Python?
Using the -u command line switch
class Unbuffered: def __init__(self, stream): self.stream = stream def write(self, data): self.stream.write(data) self.stream.flush() def __getattr__(self, attr): return getattr(self.stream, attr) import sys sys.stdout=Unbuffered(sys.stdout)
Setting the PYTHONUNBUFFERED environment variable
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
Answer
Correct Answer:
Using the -u command line switch class Unbuffered: def __init__(self, stream): self.stream = stream def write(self, data): self.stream.write(data) self.stream.flush() def __getattr__(self, attr): return getattr(self.stream, attr) import sys sys.stdout=Unbuffered(sys.stdout) Setting the PYTHONUNBUFFERED environment variable
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
457. Which of the following is the base language of Python?
Smalltalk
C
C++
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
458. Which of the following is a stored string.printable constant?
string.digits
string.letters
string.punctuation
string.whitespace
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
459. Which of the following statement/s is/are correct about lossy or lossless compression?
Lossy compression allows you to reproduce something "pretty much like" the original data set
Decompression transformation for lossless compression can reproduce exactly the original data
Most often lossy compression techniques are used for images, sound files, and video
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
460. The Python interpreter is very open to introspection. You can examine and modify many aspects of the Python runtime environment. Which of the following modules is used to retrieve information about Python runtime?
system
sys
Runtime
env
Note: This Question is unanswered, help us to find answer for this one
Check Answer
461. Which of the following is the correct prototype for the 'open' function of the file class in python 2.2+?
open(fname [,mode [,buffering]])
open(fname [,buffering [,mode]])
open(fname [,mode])
open(fname,mode,buffering)
open(fname,buffering,mode)
None of the above
Answer
Correct Answer:
open(fname [,mode [,buffering]])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
462. Which of the following are correctly using 'self'?
self = 'spam'
object.__repr__(self)
string.upper(self)
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
463. Headers are passed with Internet calls. Which of the following exceptions occur if there is an error in a header?
MultipartConversionError
HeaderParseError
HeaderError
None of the above
Answer
Correct Answer:
HeaderParseError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
464. The Python standard library contains intermediate-level modules to support all the most popular internet communication protocols. Which of the following is a valid module for Internet communication in Python?
poplib
smtplib
ftplib
httplib
imaplib
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
465. Read the following statement and state whether it is true or false: Strings and files provide a storage container for an unlimited amount of (textual) information that is directly structured only by the linear position of the bytes.
True
False
Note: This Question is unanswered, help us to find answer for this one
Check Answer
466. You have a script file where no script and no arguments are given. Which of the following will be the value of sys.argv[0]?
Empty string
0
1
Garbage value
None of the above
Answer
Correct Answer:
Empty string
Note: This Question is unanswered, help us to find answer for this one
Check Answer
467. Declaring a function is simply the preferred way of describing an object and binding it to a name. Which of the following statements bind an "anonymous" function to a name?
add1 = lambda x,y: x+y
def add2(x, y):... return x+y
add1 = anon x,y: x+y
All of the above
Answer
Correct Answer:
add1 = lambda x,y: x+y
Note: This Question is unanswered, help us to find answer for this one
Check Answer
468. Read the following statements:
>>> import string
>>> str = "Mary had a lamp in her Hand"
>>> str = string.replace(str, 'ha', 'stan')
>>> str
Which of the following will be the output?
Mary had a lamp in her Hand
Mary stand a lamp in her Hand
Mary had a lamp in her stannd
Mary stand a lamp in her stannd
Answer
Correct Answer:
Mary stand a lamp in her Hand
Note: This Question is unanswered, help us to find answer for this one
Check Answer
469. What will be the output of the following statements:
>>> letlist = ('a','B','Z','r','w')
>>> for c in letlist: print c, # inserts spaces
aBZrw
a B Z r w
...a B Z r w
None of the above
Answer
Correct Answer:
a B Z r w
Note: This Question is unanswered, help us to find answer for this one
Check Answer
470. Which of the following statements is correct for the interpreter when it is in interactive mode?
commands are read from a tty
Signs (" ") for primary prompt
Signs (" ") for secondary prompt
Answer
Correct Answer:
commands are read from a tty
Note: This Question is unanswered, help us to find answer for this one
Check Answer
471. What is the output of the following statement?
>>> 1j * 1J
(j2)
(-1+0j)
(1j2)
(2+0j)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
472. The central concept in Python programming is that of a namespace. Each context (i.e., scope) in a Python program has a hierarchically organized collection of namespaces available to it. Which of the following types of scopes can be used in namespaces?
Builtin
Global
Local
Nested
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
473. How do you refer to the null object in Python?
none
None
null
Null
Note: This Question is unanswered, help us to find answer for this one
Check Answer
474. Python is a platform independent language and it is available on different platforms. Which of the following is not related to Python?
DLL
COM
Distributed Objects
Networking
None of the above
Answer
Correct Answer:
None of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
475. Read the following statements: >>> word = 'Help' + 'A' >>> '<' + word*5 + '>' Which of the following will be the output of the above code snippet?
HelpAHelpAHelpAHelpAHelpA
HelpA5
HelpA*5
An error
None of the above
Answer
Correct Answer:
HelpAHelpAHelpAHelpAHelpA
Note: This Question is unanswered, help us to find answer for this one
Check Answer
476. Which of the following types is correct for objects created by the built-in buffer() function?
types.BufferType
types.Buffer
types.TypeBuffer
types.BuffType
Answer
Correct Answer:
types.BufferType
Note: This Question is unanswered, help us to find answer for this one
Check Answer
477. You need to implement an email management system. You want to receive and send the emails from your Python application. Which of the following protocols will be used for email implementation?
telnetlib
smtplib
ftplib
None of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
478. Examine the following prototype for the 'open' function of the file class in Python 2.2+: open(fname [,mode [,buffering]]) Which of the following is correct for the 'buffering' argument?
0 for none
1 for line oriented
An integer larger than 1 for number of bytes
All of the above
Answer
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
479. Read the following statements: Statement 1: The conditions used in 'while' and 'if' statements can contain only comparison operators. Statement 2: The operators 'is' and 'is not' compare whether two objects are really the same object. Which of the following is correct?
Statement 1 is true but statement 2 is false
Statement 1 is false but statement 2 is true
Both statements are true
Both statements are false
Answer
Correct Answer:
Statement 1 is false but statement 2 is true
Note: This Question is unanswered, help us to find answer for this one
Check Answer
480. What will be the output of the following statements:
>>> import string
>>> s = 'little fox\011jumps over a lazy dog'
>>> string.expandtabs(tabsize=1, s=s)
little fox jumps over a lazy dog
little fox\011jumps over a lazy dog
little fox jumps over a lazy dog
little fox\011 jumps over a lazy
Answer
Correct Answer:
little fox jumps over a lazy dog
Note: This Question is unanswered, help us to find answer for this one
Check Answer
481. Read the following statements: >>> word = 'Help' + 'A' >>> word[:2] Which of the following will be the output of the above code?
lpA
He
pA
lp
Note: This Question is unanswered, help us to find answer for this one
Check Answer
482. Which statement would you use to import a module called "foo"?
import(foo)
import: foo
import foo
import foo;
Answer
Correct Answer:
import foo
Note: This Question is unanswered, help us to find answer for this one
Check Answer
483. How many positional arguments can be passed to the below function def my_func(*args): pass
infinite
0
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
484. How is Python's code organized?
Logical blocks are enclosed in brackets { }.
Logical blocks share the same indentation.
Logical blocks are indented and enclosed in parentheses ().
Logical blocks are separated by keywords.
Answer
Correct Answer:
Logical blocks share the same indentation.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
485. Given a X = 'a b c', what does X.split() return?
''a', 'b', 'c''
['a', 'b', 'c']
['a b c']
('a', 'b', 'c')
Answer
Correct Answer:
['a', 'b', 'c']
Note: This Question is unanswered, help us to find answer for this one
Check Answer
486. Which of these functions would be used to display the internals of an object instance
help()
instance()
dir()
vars()
print()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
487. There are two strings, "a" and "b" with same values ,a="harmeet" and b="harmeet". Which one of the following case is true?
Both strings "a" and "b" refer to one single string with value "harmeet"
Both strings a and b refer to different strings having same value.
Answer
Correct Answer:
Both strings "a" and "b" refer to one single string with value "harmeet"
Note: This Question is unanswered, help us to find answer for this one
Check Answer
488. Which of the following is a module in the Python Standard Library?
unixpath
winpath
solarispath
linuxpath
macpath
Note: This Question is unanswered, help us to find answer for this one
Check Answer
489. All Warnings in Python are subclassed from:
AbstractWarning
BaseWarning
Warning
Note: This Question is unanswered, help us to find answer for this one
Check Answer
490. What expression evaluates to 'python 2.7'?
"%s %r" % ('python', '2.7')
"%s %s" % ('python', 2.7)
"%s %d" % ('python', 2.7)
all answers are correct
"%s %f" % ('python', 2.7)
Answer
Correct Answer:
"%s %s" % ('python', 2.7)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
491. In Python 3.x, what must also happen if a class defines __eq__() ?
It must also define __ne__().
It must also define __hash__() if its instances are mutable and need to be hashable.
It must also define __ne__(), __gt__() and __lt__() if its instances need to be sortable.
It must also define __hash__() if its instances are immutable and need to be hashable.
It must also define __cmp__() if its instances need to be sortable.
Answer
Correct Answer:
It must also define __hash__() if its instances are immutable and need to be hashable.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
492. The function apply has the same functionality as:
map
list comprehensions
functools.wraps
*args, **kwargs
Answer
Correct Answer:
*args, **kwargs
Note: This Question is unanswered, help us to find answer for this one
Check Answer
493. What will be the result of the following expression 7 // 3 + 7 // -3?
-1
0
1
There is no // operator in Python.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
494. Consider a method x.foo decorated with @classmethod: What would x.foo.__class__ return?
<type 'dictionary'>
<type 'classmethod'>
<type 'method'>
<type 'instancemethod'>
<type 'object'>
Answer
Correct Answer:
<type 'instancemethod'>
Note: This Question is unanswered, help us to find answer for this one
Check Answer
495. In Python 3.2's stand CPython implementation, all built-in types support weak-referencing.
False
True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
496. In a Python 3 class declared as "Child(Base)", what is the correct way for a method "foo()" to call its base implementation?
Base.foo(self)
super().foo()
super(Child).foo()
Child.foo(self)
super(Base, self).foo()
Answer
Correct Answer:
super().foo()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
497. Is it possible to use Java classes in Jython?
Yes, but the programmer must use a special Jython syntax for calling Java classes
No
Yes, they must be treated like Java classes
Yes, they must be treated like Python classes
Answer
Correct Answer:
Yes, they must be treated like Python classes
Note: This Question is unanswered, help us to find answer for this one
Check Answer
498. The built in method reversed() returns:
The same thing as original_sequence[::-1]
An iterator that traverses the original sequence backwards
The original sequence, backwards
Answer
Correct Answer:
An iterator that traverses the original sequence backwards
Note: This Question is unanswered, help us to find answer for this one
Check Answer
499. Which of these Python 2.7 APIs provides a high (for the platform) resolution wall-clock timer?
None of these
time.clock()
posix.clock_gettime()
ntmodule.QueryPerformanceCounter()
All of these
Answer
Correct Answer:
None of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
500. In the Python 2.x interpreter, which piece of code will print "hello world" with only a space between the words?
None of these
print "hello" + "world"
print "hello\tworld"
print "hello"; print "world"
print "hello",; print "world"
Answer
Correct Answer:
print "hello",; print "world"
Note: This Question is unanswered, help us to find answer for this one
Check Answer
501. If a = 1 and b = 2, what does the expression "a and b" return?
False.
2
3
True.
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
502. If you wanted to determine the type of an image with the stdlib, you would use functions from which module?
Image
pimg
types
imghdr
Note: This Question is unanswered, help us to find answer for this one
Check Answer
503. Which of the following is equivalent to "x = a + b"?
x = sum({a, b})
from math import fsum; x = fsum([a, b])
x = a.plus(b)
x = a.__add__(b)
from operator import add; x = add(a, b)
Answer
Correct Answer:
from operator import add; x = add(a, b)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
504. The CPython implementation garbage collector detects reference cycles by ___.
Traversing all references using an adapted breadth first search. If the process visits a node it has already seen, there is a reference cycle containing that node
Determining all reachable objects, and deleting all other unreachable objects from the stack
Keeping track of all container objects and comparing the number of references to a container to its total reference count
Selecting an object at random and checking if it is in a reference cycle
None of these, the python standard does not allow reference cycles
Answer
Correct Answer:
Keeping track of all container objects and comparing the number of references to a container to its total reference count
Note: This Question is unanswered, help us to find answer for this one
Check Answer
505. What does the code 'import sndhdr; sndhdr.what(filename)' Do?
Determines the type of sound file it is by inspecting the filename
Determines what Bitrate the sound file is
Determines the location of the sound file on disk
Determines the type of sound file it is by inspecting the file headers
Answer
Correct Answer:
Determines the type of sound file it is by inspecting the filename
Note: This Question is unanswered, help us to find answer for this one
Check Answer
506. The distribute library is a fork of
pip
distutils2
distutils
setuptools
Answer
Correct Answer:
setuptools
Note: This Question is unanswered, help us to find answer for this one
Check Answer
507. Given an open file object f, what does f.read() result in when the end of the file has been reached?
It returns -1
It returns False
It raises EOFError
It returns None
It returns '' (an empty string)
Answer
Correct Answer:
It returns '' (an empty string)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
508. If a and b are strings, which of the following is equivalent to [a] + [b] ?
[a,b]
[a + b]
[a].append(b)
[a].extend([b])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
509. If I do "x = X(); y = x[1, 2:3, 4:5:6]", what type is passed to x.__getitem__?
extended slice
plain slice
tuple
list of ints
dict of ints
Note: This Question is unanswered, help us to find answer for this one
Check Answer
510. Which statement change the variable line from " td main " to "td main "
line.replace(","tr>") ">
line = ".join(line.split("td>")">
line.replace(
line = line.replace(
Answer
Correct Answer:
line = ".join(line.split("td>")">
Note: This Question is unanswered, help us to find answer for this one
Check Answer
511. All Exceptions in Python are subclassed from
BaseException
AbstractException
Exception
Answer
Correct Answer:
BaseException
Note: This Question is unanswered, help us to find answer for this one
Check Answer
512. When searching for imports Python searches what path?
os.import_path
sys.PYTHONPATH
All of these
sys.path
Note: This Question is unanswered, help us to find answer for this one
Check Answer
513. Python has which 3 different profilers in the standard library?
cProfile, profile, hotshot
nose, timeit, profile
profile, trace, pdb
hotshot, nose, profile
Answer
Correct Answer:
cProfile, profile, hotshot
Note: This Question is unanswered, help us to find answer for this one
Check Answer
514. Suppose a= [1,2,3,4]. What will be the value of 'a' after we execute this statement a= a.append(5) ?
[1,2,3,4]
[1,2,3,4,5]
Error message
None
Note: This Question is unanswered, help us to find answer for this one
Check Answer
515. What would be output of following? import sys d = {} for x in range(4): d[x] = lambda : sys.stdout.write(x) d[1]() d[2]() d[3]()
012
333
KeyError
123
Note: This Question is unanswered, help us to find answer for this one
Check Answer
516. What is the Python 3 equivalent of the following Python 2 code: print >> f, "Smarterer", "Tests",
print(> f">
print(
print(
fileprint(f, (
print((
Note: This Question is unanswered, help us to find answer for this one
Check Answer
517. At minimum, what must a metaclass be?
A class with a 'meta' attribute.
A callable object.
An instance of itself.
A class defined within a class.
Answer
Correct Answer:
A callable object.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
518. Which of the following will produce the same output?
print "word" in [] == False and print "word" in ([] == False)
print ("word" in []) == False and print "word" in ([] == False)
All three will produce the same output.
None of these combinations.
print "word" in ([] == False) and print "word" in [] == False
Answer
Correct Answer:
None of these combinations.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
519. Which option creates a list of key value tuples from a dictionary sorted by value? d = {'a':1, 'b':2, 'c':3}
sorted(d.items(), value=operator.itemgetter(1))
sorted(d.items(), value=operator.itemgetter(0))
sorted(d.items(), key=operator.itemgetter(1))
sorted(d.items(), key=lambda x[1])
Answer
Correct Answer:
sorted(d.items(), key=operator.itemgetter(1))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
520. Which of the following is not a Python standard library module for processing arguments to a program?
getargs
getopt
optparse
argparse
Note: This Question is unanswered, help us to find answer for this one
Check Answer
521. When reading Comma Separated Value formatted files, the csv module is frequently used. In which mode must files be opened for use with the csv module?
Binary mode in Python 2, text mode in Python 3
Binary mode
Text mode
Text mode in Python 2, binary mode in Python 3
Answer
Correct Answer:
Binary mode in Python 2, text mode in Python 3
Note: This Question is unanswered, help us to find answer for this one
Check Answer
522. Python has both a math library and a cmath library. How are they related?
cmath is for complex numbers while math is for rational numbers
cmath is the math library written in C for speed
Answer
Correct Answer:
cmath is for complex numbers while math is for rational numbers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
523. What is the result of the expression: print [k(1) for k in [lambda x: x + p for p in range(3)]]?
[4, 4, 4]
[1, 2, 3]
[3, 3, 3]
This expression will produce a syntax error.
Answer
Correct Answer:
[3, 3, 3]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
524. Which of the following built-in identifiers may not be assigned to (as of Python 2.4)?
None
object
NotImplemented
__builtins__
type
Note: This Question is unanswered, help us to find answer for this one
Check Answer
525. Given a list: lst = ['alpha', 'beta', '', 'gamma']. What will be returned by the function: filter(None, lst)?
A NameError exception
['alpha', 'beta', 'gamma']
['alpha', 'beta', '', 'gamma']
['']
Answer
Correct Answer:
['alpha', 'beta', 'gamma']
Note: This Question is unanswered, help us to find answer for this one
Check Answer
526. When resolving a name to an object in a function, which of these is not a scope considered?
Builtin
Closed over
Local
Class
Global
Answer
Correct Answer:
Closed over
Note: This Question is unanswered, help us to find answer for this one
Check Answer
527. In Python 2.7 the Counter object acts most like a:
dictionary
set
list
Answer
Correct Answer:
dictionary
Note: This Question is unanswered, help us to find answer for this one
Check Answer
528. How often is the value of y initialized in the following class? >>> class X(): >>> def x(self,y = []): >>> return y
Once per function call.
Once.
Once per class instance.
Twice.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
529. Which of these arguments is not passed to a metaclass when it is instantiated?
Class dictionary
Class bases
Class name
Class module
Answer
Correct Answer:
Class module
Note: This Question is unanswered, help us to find answer for this one
Check Answer
530. How are imaginary numbers denoted in Python?
Using escape sequence \j
Using suffix i
Using suffix j
Using escape sequence \n
Answer
Correct Answer:
Using suffix j
Note: This Question is unanswered, help us to find answer for this one
Check Answer
531. This decorated function in python: @foo def bar(): ... is equal to:
def bar(): ... foo(bar)
def bar(): ... bar = foo()(bar)
def bar(): ... foo()(bar)
def bar(): ... bar = foo(bar)
Answer
Correct Answer:
def bar(): ... bar = foo(bar)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
532. Given the following code, what will be printed to the standard output? x = 5 def some_function(): print(x) x = 6 some_function() print(x)
6, then 6
UnboundLocalError (and traceback)
5, then 6
5, then 5
Answer
Correct Answer:
UnboundLocalError (and traceback)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
533. If you use UTF-8 characters in your source file, what should you do to make it work under Python 2?
# coding:utf-8
# -*- coding: utf-8 -*-
# vim: set fileencoding=utf-8 :
Any of these
Answer
Correct Answer:
Any of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
534. What common convention do Python programs use to indicate internal-only APIs?
Two leading and two trailing underscores
A single underscore prefix
A double underscore prefix
A suffix of "_private"
A prefix of "private_"
Answer
Correct Answer:
A single underscore prefix
Note: This Question is unanswered, help us to find answer for this one
Check Answer
535. What's the difference between input() and raw_input() in Python 2.x?
raw_input() preserves invisible characters, linebreaks, etc., while input() cleans them up.
raw_input() evaluates input as Python code, while input() reads input as a string.
raw_input() reads input as a string, while input() reads it as unicode.
raw_input() reads input as a string, while input() evaluates input as Python code.
raw_input() doesn't cook input, while input() sears it to a nice medium-rare.
Answer
Correct Answer:
raw_input() reads input as a string, while input() evaluates input as Python code.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
536. What standard library module would you use to find the names and default values of a function’s arguments?
signature
argsig
functools
inspect
sys.argv
Note: This Question is unanswered, help us to find answer for this one
Check Answer
537. What is printed by print( r"\nthing" )?
r"\nthing"
r\nthing
\nthing
"\nthing"
A new line and then the string: thing
Note: This Question is unanswered, help us to find answer for this one
Check Answer
538. The super() function works for:
new style classes
old style classes
Both new and old style classes
Answer
Correct Answer:
new style classes
Note: This Question is unanswered, help us to find answer for this one
Check Answer
539. print max([3,4,-5,0],key=abs) returns?
5
4
Syntax error
0
-5
Note: This Question is unanswered, help us to find answer for this one
Check Answer
540. Given mydict = {'foo': 'hello', 'bar': 'world'} Which of the below would evaluate to True ?
mydict.type == {}
import types type(mydict) == types.DictionaryType
type(mydict) == {}
type(mydict) = {}
import types type(mydict) = types.DictionaryType
Answer
Correct Answer:
import types type(mydict) == types.DictionaryType
Note: This Question is unanswered, help us to find answer for this one
Check Answer
541. A function can be declared using "def double(x): return x+x" or using "double = lambda x: x+x". What is the difference between these declarations?
The first (def) defines "double" in the global or class namespace, while the second (lambda) only sets a local variable.
The first (def) has its "__name__" attribute initialized to "double", but the second (lambda) does not.
No difference: the declarations have the same effect.
CPython can optimize and execute the first (def) more efficiently than the second (lambda).
The second (lambda) can be used as a function argument, as in "map(double, l)", but the first (def) cannot.
Answer
Correct Answer:
The first (def) has its "__name__" attribute initialized to "double", but the second (lambda) does not.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
542. Which of the following if statements will result in an error?
if ( 0 & 1/0 ):
if ( None and 1/0 ):
if ( 0 and 1/0 ):
if ( 1 ): ... elif ( 1/0 ):
Answer
Correct Answer:
if ( 0 & 1/0 ):
Note: This Question is unanswered, help us to find answer for this one
Check Answer
543. What will be the output: a = [1, 2, 3, 4] for (i, x) in enumerate(a): for (j, y) in enumerate(a[i:]): print j, print
1 2 3 4 1 2 3 1 2 1
0 1 2 3 1 2 3 2 3 3
0 1 2 3 0 1 2 0 1 0
1 2 3 4 2 3 4 3 4 4
Answer
Correct Answer:
0 1 2 3 0 1 2 0 1 0
Note: This Question is unanswered, help us to find answer for this one
Check Answer
544. What does a method name that starts with two underscores but does not end with two underscores signify?
The method's name will be mangled to make it unlikely the method will be overridden in a subclass.
This construction denotes a method in a class which can be called from within other classes.
It is an internal method of a class. It can be called directly and indirectly.
There is no reason to do that.
Answer
Correct Answer:
The method's name will be mangled to make it unlikely the method will be overridden in a subclass.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
545. import itertools p = itertools.permutations([1, 2]) f = filter(lambda x: x[0] % 2 == 0, p) What is the value of f?
[(2, 1)]
[True, False]
[(1, 2)]
[False, True]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
546. x = reduce(lambda x,y:x+y,[int(x) for x in "1"*10]) What is the value of x?
Syntax Error
"1111111111"
10
2568988
Note: This Question is unanswered, help us to find answer for this one
Check Answer
547. Assume: a = 1 b = 4 c = (a == 'text') and a or b. What is the value of c?
None
4
'text1'
'text'
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
548. What is the result of print(2 <> 3) in Python 3?
SyntaxError
True
-1
1
False
Answer
Correct Answer:
SyntaxError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
549. Which of these can sort the following by value? sample_dict
sorted(sample_dict.items(), key=lambda d:d[1])
sorted(sample_dict.items(), key=lambda d:d[0])
sorted(sample_dict.items(), value=lambda d:d[1] )
sorted(sample_dict.items(), value=lambda d:d[0] )
Answer
Correct Answer:
sorted(sample_dict.items(), key=lambda d:d[1])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
550. what is a valid way to run asyncio loop.
loop.start()
loop.run_until_complete()
loop.begin()
loop.run_forever()
loop.start_forever()
Answer
Correct Answer:
loop.run_forever()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
551. What do you do to implicitly concatenate two literal strings?
Separate them with '*' characters
Separate them with commas
Put the whole expression in triple-quotes """
Write them one after another
Answer
Correct Answer:
Write them one after another
Note: This Question is unanswered, help us to find answer for this one
Check Answer
552. Which of these lines will reverse a list named "foo"?
foo = reverse(foo)
All of these
foo = foo[::-1]
foo = foo ** -1
Answer
Correct Answer:
foo = foo[::-1]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
553. Using the python string module, what would the following return: string.join(['Python', 'is', 'great']) ?
'Python is great'
Python is great
A 'SyntaxError: invalid syntax' exception
''Python''is''great'
Answer
Correct Answer:
'Python is great'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
554. The code 'lambda x: return x' will do what?
Raise a NameError Exception
Return x
Raise a SyntaxError Exception
Raise a ValueError Exception
Raise a TypeError Exception
Answer
Correct Answer:
Raise a SyntaxError Exception
Note: This Question is unanswered, help us to find answer for this one
Check Answer
555. If a="holy", b="grail", and c=None, what does the following expression return? a or b or c
'holy'
True
False
'grail'
None
Note: This Question is unanswered, help us to find answer for this one
Check Answer
556. How would you write the following with a list comprehension? x = [] for i in range(5): x.append([]) for j in range(10): x[-1].append(j)
x = [[i for i in range(5)] for j in range(10)]
x = [i for i in range(5) for j in range(10)]
x = [i for i in range(10) for j in range(5)]
x = [[i for i in range(10)] for j in range(5)]
Answer
Correct Answer:
x = [[i for i in range(10)] for j in range(5)]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
557. What is " __doc__" for in Python?
return documentation string of object or none
return object document or none
return class information or none
return documentation string of class or none
Answer
Correct Answer:
return documentation string of object or none
Note: This Question is unanswered, help us to find answer for this one
Check Answer
558. Which of the following is NOT python ORM?
peewee
Doctrine
SQLAlchemy
Storm
Note: This Question is unanswered, help us to find answer for this one
Check Answer
559. What will the output of the following statement be? print "%s is awesome !" % python
%s is awesome !
pythons is awesome !
python is awesome !
NameError
None
Answer
Correct Answer:
NameError
Note: This Question is unanswered, help us to find answer for this one
Check Answer
560. What is a future statement?
A variable assignment for an instance of a class that has not yet been created.
A proposal for a feature that should be implemented in the Python Standard Library in future releases.
A declaration of a method that has not yet been implemented.
A reference to a variable that has not yet been instantiated.
A directive to the compiler that a particular module should be compiled using syntax or semantics that will be available in a specified future release of Python.
Answer
Correct Answer:
A directive to the compiler that a particular module should be compiled using syntax or semantics that will be available in a specified future release of Python.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
561. Which of the following can be used as a dictionary key?
tuple
set
list
dictionary
None of Above
Note: This Question is unanswered, help us to find answer for this one
Check Answer
562. Given array = [1, 2, 3, 4, 5, 6] what is the value of array after the following statement? del array[1:3]
[3, 4, 5, 6]
[1, 4, 5, 6]
[1, 5, 6]
[4, 5, 6]
Answer
Correct Answer:
[1, 4, 5, 6]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
563. Which will raise 2 to the 24th power?
x = 2 ** 24
import math; x = math.pow(2, 24)
x = 1 << 24
(Any Of These)
Answer
Correct Answer:
(Any Of These)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
564. What will be the value of a in: a = set(); a.add(['b'])?
set(['b'])
TypeError: unhashable type: 'list'
['b']
('b')
Answer
Correct Answer:
TypeError: unhashable type: 'list'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
565. How do you increase a datetime variable called "dt" with three days?
dt = dt.future(days=3)
dt += datetime.timedelta(3)
dt += (0, 0, 3, 0, 0, 0)
dt += 3
dt = datetime.datetime(dt.year, dt.month, dt.day + 3, dt.hour, dt.minute, dt.second)
Answer
Correct Answer:
dt += datetime.timedelta(3)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
566. What is the correct way to get the exception as variable in except statement?
A) except Exception:
C is correct in Python 2, D is correct in Python 3, and Python 2.6 and 2.7 accepts both.
D) except Exception as e:
B) except (Exception, e):
C) except Exception, e:
Answer
Correct Answer:
C is correct in Python 2, D is correct in Python 3, and Python 2.6 and 2.7 accepts both.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
567. In Python 2.x, 'round(1)' and 'abs(-1)' will produce identical results.
True, both quantities are identical.
The second expression will produce a SyntaxError exception.
False, the round() produces a float while the abs() produces an integer.
The first expression will produce a NameError exception.
Answer
Correct Answer:
False, the round() produces a float while the abs() produces an integer.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
568. True or False: you can create a list of the values in a dict sorted by the value's related keys
False
True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
569. Python is a garbage collected language. The CPython implementation primarily accomplishes this memory management via _____.
reference counting
overridable __del__ methods called finalizers
the gc garbage collection interface
the mark and sweep algorithm
Answer
Correct Answer:
reference counting
Note: This Question is unanswered, help us to find answer for this one
Check Answer
570. What will typing the following at the Python interpreter produce? >>> num = [2,3,5,7,11] >>> len(num) // min(num)
10.0
SyntaxError exception
2
2.5
2.0
Note: This Question is unanswered, help us to find answer for this one
Check Answer
571. What will typing the following at the Python interpreter produce? sequence = ['A','B','C','D','E','F'] ; sequence[1:2:3]
[]
'B'
['B']
['B', 'C']
Note: This Question is unanswered, help us to find answer for this one
Check Answer
572. If you wanted to copy a tree of files with the Python standard library, you would look at which module?
cmd
shlex
sys
shutil
Note: This Question is unanswered, help us to find answer for this one
Check Answer
573. What does the function sys.modules.keys() do?
Returns a list of all available modules.
Returns a list of all loaded modules.
Reloads a module and passed a parameter to a function.
Loads a list of all modules in central repository.
Answer
Correct Answer:
Returns a list of all loaded modules.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
574. How can the whole numbers from 1 to 10 be totaled?
sum(i for i in xrange(1, 11))
sum(i for i in range(1, 10))
sum(range(1,10))
total = 0 for i in range(1,11): for j in range(i): total++
Answer
Correct Answer:
sum(i for i in xrange(1, 11))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
575. a = range(1, 10) m = map(lambda x: x % 2 == 0, a) What is the value of m
[False, True, False, True, False, True, False, True, False]
[False, True, False, True, False, True, False, True, False, True]
[2, 4, 6, 8, 10]
[1, 0, 1, 0, 1, 0, 1, 0, 1]
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
Answer
Correct Answer:
[False, True, False, True, False, True, False, True, False]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
576. How can one merge two dicts? >>> x = {'a':1, 'b': 2} >>> y = {'b':10, 'c': 11} result: {'a': 1, 'b': 10, 'c': 11}
z = x.copy() z.update(y)
z = dict(x, **y)
All of these.
z = dict(list(x.items()) + list(y.items()))
Answer
Correct Answer:
All of these.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
577. Is it possible to link a Python program to code written in C?
Yes; the C code can be in a form of a dynamically or a statically linked library.
Yes, but C code must be provided in a form of statically linked library.
No, it is impossible.
Yes, but the C code must be provided in a form of a dynamically linked library.
Answer
Correct Answer:
Yes; the C code can be in a form of a dynamically or a statically linked library.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
578. Given the list called my_list, what would the following slice notation give you: my_list[-1:-5:-1]
Up to 4 items, starting from the last item in the list and indexed in reverse order.
No items, since the beginning and ending indices are the same
A subset of the list, from the 4th item to the end of the list, in reverse order.
An IndexError exception. Negative numbers in slice notation have no meaning.
2 items, starting from the 5th index from the end of the list
Answer
Correct Answer:
Up to 4 items, starting from the last item in the list and indexed in reverse order.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
579. What type of error does "type('1') is int" return?
NameError
SyntaxError
TypeError
None; it returns True
None; it returns False
Answer
Correct Answer:
None; it returns False
Note: This Question is unanswered, help us to find answer for this one
Check Answer
580. What will be returned by the statement "12345"[1:-1] ?
12345
'234'
234
'1234'
1234
Note: This Question is unanswered, help us to find answer for this one
Check Answer
581. The following lines do the same work. What is the difference between them? lines = string.split(text, '\n') and lines = text.split('\n')
No import is required by the second line.
No import is required by the first line.
An import is required by the second line.
There is no difference.
Answer
Correct Answer:
No import is required by the second line.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
582. Which is _not_ a way to control how Python finds the implementation of modules for import?
Change the contents of sys.path
Change the contents of sys.path_hooks
Change the contents of sys.api_version
Change the contents of sys.meta_path
Change the PYTHONPATH environment variable
Answer
Correct Answer:
Change the contents of sys.api_version
Note: This Question is unanswered, help us to find answer for this one
Check Answer
583. How is the ternary operator written in Python 2.5+?
if a == b then 'equal' else 'not equal'
'equal' if a == b : 'not equal'
a == b? 'equal': 'not equal'
'equal' if a == b else 'not equal'
Answer
Correct Answer:
'equal' if a == b else 'not equal'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
584. In a Python 2 new-style class declared as "Child(Base)", what is the correct way for a method "foo()" to call its base implementation?
Child.frob(super)
super(Child, self).foo()
Child.frob(self)
super(Base, self).foo()
super(Child).frob()
Answer
Correct Answer:
super(Child, self).foo()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
585. Which of these will allow you to put more than one statement in one line of text?
A colon
A triple-quoted string
An extra indent
None of these
A semicolon
Answer
Correct Answer:
A semicolon
Note: This Question is unanswered, help us to find answer for this one
Check Answer
586. Which datatypes are immutable in Python
Float, Tuple, List, String
Dict, List, Set, Int
Tuple, Int, Float, String
Set, Tuple, Float, List
Dict, Tuple, String, Set
Answer
Correct Answer:
Tuple, Int, Float, String
Note: This Question is unanswered, help us to find answer for this one
Check Answer
587. What will typing the following at the Python interpreter produce? lang = list('Python') ; lang[:-4]
['t', 'h', 'o', 'n']
['P', 'y']
['o', 'n']
['P', 'y', 't', 'h']
Answer
Correct Answer:
['P', 'y']
Note: This Question is unanswered, help us to find answer for this one
Check Answer
588. def fn(a, *b, **c): print(c) fn(5) What will be the output?
5
25
255
{}
Error
Note: This Question is unanswered, help us to find answer for this one
Check Answer
589. What method is usually used to return unicode representation of an object?
unicode
__str__
str
__unicode__
utf-8
Answer
Correct Answer:
__unicode__
Note: This Question is unanswered, help us to find answer for this one
Check Answer
590. What is the output of the following script? def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2)) print(f(3))
AttributeError
None
[1] [2] [3]
[1] [1, 2] [1, 2, 3]
Answer
Correct Answer:
[1] [1, 2] [1, 2, 3]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
591. What does the following code do: @something def some_function(): pass
Adds `something` to `some_function`'s `__annotations__` field
It raises a `SyntaxError`
Silences all errors raised by `something` while it is called.
Calls `something`, passing in `some_function` and rebinds the name `some_function` to the return value of `something`.
Calls `something`, passing in `some_function` (`some_function` remains unchanged).
Answer
Correct Answer:
Calls `something`, passing in `some_function` and rebinds the name `some_function` to the return value of `something`.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
592. Is it possible to check for more than one error in one except line?
No, it is not possible.
Yes, if the exception types are enclosed in curly braces.
Yes, if the exception types are enclosed in square brackets.
Yes, if the exception types are enclosed in parentheses.
Answer
Correct Answer:
Yes, if the exception types are enclosed in parentheses.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
593. filter(function, iterable) is equivalent to:
[item for item in iterable if function(item)] if function is not None
[item for item in iterable if function(item)] if function is None
[item for item in iterable if item] if function is not None
Answer
Correct Answer:
[item for item in iterable if function(item)] if function is not None
Note: This Question is unanswered, help us to find answer for this one
Check Answer
594. Given str="code", what will be the result of the expression str[0] = 'm'?
A TypeError. Strings in Python are immutable.
"mcode"
"code"
"mode"
Answer
Correct Answer:
A TypeError. Strings in Python are immutable.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
595. In order to display a value in the interactive interpreter, Python uses what method of a class?
__unicode__
__repr__
__str__
__hash__
Note: This Question is unanswered, help us to find answer for this one
Check Answer
596. What does a function glob.glob do?
There is no such function in Python.
This function search for parameters on the Internet.
This function runs a global file search on the computer.
This function takes a wildcard pattern and returns a list of matching filenames or paths.
Answer
Correct Answer:
This function takes a wildcard pattern and returns a list of matching filenames or paths.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
597. After you enter the following in a Python script and run the script, what would get printed? formatter = "%s" print formatter % (formatter)
%%s
s
none are correct
%s
Note: This Question is unanswered, help us to find answer for this one
Check Answer
598. What is a persistent dictionary?
A dictionary of a rather small size which is loaded to a cache memory for a faster performance.
A dictionary which is loaded automatically when Python's interpreter is started.
A sequence of name and value pairs which is saved to a disk, that will endure between multiple program runs.
A dictionary in which data are stored in a sorted order.
Answer
Correct Answer:
A sequence of name and value pairs which is saved to a disk, that will endure between multiple program runs.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
599. What gets printed: a = [0] b = [a] *4 a[0] = 2 print(b)
[[2], [2], [2], [2]]
[[0], [0], [0], [0]]
[0]
[[2], [0], [0], [0]]
[2]
Answer
Correct Answer:
[[2], [2], [2], [2]]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
600. When opening a file, what is the difference between text mode and binary mode?
In binary mode, new line characters are converted to an OS-specific representation.
There is no difference.
In text mode, the contents are first decoded using a platform-dependent encoding.
In text mode, carriage returns are always converted to linefeed characters.
Answer
Correct Answer:
In text mode, the contents are first decoded using a platform-dependent encoding.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
601. What is a list comprehension?
A tool to concisely create lists without using common constructs, like map or filter.
A term used to designate situations when filter (or map) are used together with lambda.
A level of programming when one uses all aspects of lists with confidence.
A name of a paradigm of a list usage in Python.
Answer
Correct Answer:
A tool to concisely create lists without using common constructs, like map or filter.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
602. Which will return the 10th element of a list, or None if no such element exists?
return list_[10:]
try: return list_[9] except IndexError: return None
All of the above.
if 10 in list_: return list_[10] else: return None
Answer
Correct Answer:
try: return list_[9] except IndexError: return None
Note: This Question is unanswered, help us to find answer for this one
Check Answer
603. Which is the correct code for obtaining a random whole number from 1 to 1,000,000 in Python 2.x?
import random; x = random.choice(range(1000000))
import random; x = random.random(1000000)
import random; x = random.rand(1,1000000)
import random; x = random.randint(1,1000000)
Answer
Correct Answer:
import random; x = random.randint(1,1000000)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
604. True or False: Python packages can be imported from inside a Zip file.
False
True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
605. How can one serve current directory in http?
python -m HTTPServer
python SimpleHTTPServer
python HTTPServer
python -m SimpleHTTPServer
Answer
Correct Answer:
python -m SimpleHTTPServer
Note: This Question is unanswered, help us to find answer for this one
Check Answer
606. After executing the following code, what is the value of d? d = [0] l = lambda x: d.append(x) d.pop() l(1)
None.
This expression will produce an exception.
[2]
[1]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
607. What is 3/2?
1
It depends on the Python version
1.5
Answer
Correct Answer:
It depends on the Python version
Note: This Question is unanswered, help us to find answer for this one
Check Answer
608. Assume s = ' Hello World ' Which would remove only trailing whitespace?
s.rstrip()
' '.join(s.rsplit())
s.strip()
s.removeright(' ')
s.replace(
Answer
Correct Answer:
s.rstrip()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
609. Python's implementation for .NET is:
IronPython
P#.NET
there isn't one
Python.NET
VisualPython
Answer
Correct Answer:
IronPython
Note: This Question is unanswered, help us to find answer for this one
Check Answer
610. In the Python interpreter, if the code "L = [4, 5, 6]; Y = [L] * 2; L[1] = 0" is executed, what would be stored in Y?
Y = [[4, 5, 6], [4, 5, 6]]
Y = [[4, 0, 6], [4, 0, 6]]
Y = [8, 10, 12]
Y = [4, 0, 6, 4, 5, 6]
Answer
Correct Answer:
Y = [[4, 0, 6], [4, 0, 6]]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
611. Which of these is a valid way to implement switch-case in Python?
Python already has the "switch" keyword.
Use a list comprehension like [x for x in {1,2,3}]
Define functions and then refer to them by key with a dict.
All of the provided answers are technically correct.
Answer
Correct Answer:
Define functions and then refer to them by key with a dict.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
612. Which of these functions is a generator that will produce an endless sequence of odd numbers?
def odds(): value = 1 while True: yield value value += 2
def odds(): for value in xrange(1, maxint): yield value
def odds(): value = 1 while True: return value += 2
Answer
Correct Answer:
def odds(): value = 1 while True: yield value value += 2
Note: This Question is unanswered, help us to find answer for this one
Check Answer
613. If a file is opened by calling "input = open('data')', what does the line 'aString = input.read()' do?
Read entire file into aString as a list of line strings (with \n)
Read entire file into aString as a single string
Read next line (including \n newline) into aString as a string
Answer
Correct Answer:
Read entire file into aString as a single string
Note: This Question is unanswered, help us to find answer for this one
Check Answer
614. In what way can Python interoperate with C code?
Python C/API
All of these
Cython
ctypes
Answer
Correct Answer:
All of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
615. Given dictionary: a = {'foo': 1, 'bar': 10} Which of the following removes the last key pair value ?
a.remove(2)
del a['bar']
a.remove(bar)
del a[2]
a.remove('bar')
Answer
Correct Answer:
del a['bar']
Note: This Question is unanswered, help us to find answer for this one
Check Answer
616. What will an octal number and hexadecimal number start with?
sign (plus or minus)
There are no octal numbers in Python.
Any digit
0 (zero)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
617. Which is NOT an implementation of the Python Language?
CPython
IronPython
PyPi
Jython
PyPy
Note: This Question is unanswered, help us to find answer for this one
Check Answer
618. Which of these are built-in test modules of Python?
unittest, doctest, django.test
unittest, doctest, __test__
unittest, doctest, testclient
unittest, doctest
Answer
Correct Answer:
unittest, doctest
Note: This Question is unanswered, help us to find answer for this one
Check Answer
619. What does the following do: a=1,2,3
Creates or updates the variable "a" with the sequence (1,2,3)
Generates an execution error
Creates or updates the variable "a" with the list [1,2,3]
Creates or updates the variable "a" with the number 3
Generates a compilation error
Answer
Correct Answer:
Creates or updates the variable "a" with the sequence (1,2,3)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
620. What is the result of ("%g" % 74), '7' ?
('74', '7')
(74, 7)
('74', '7.00')
('74', '7.0')
Answer
Correct Answer:
('74', '7')
Note: This Question is unanswered, help us to find answer for this one
Check Answer
621. Distutils uses a file called ____ to act as the entry point to managing a package.
setup.py
distutils.py
install.py
package.py
run.py
Note: This Question is unanswered, help us to find answer for this one
Check Answer
622. How many lists are created from the following? a = [] b = a c = a[:]
1
2
3
None.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
623. Which of these is not a common Python web framework?
web.py
PyScripts
Pylons
Django
Answer
Correct Answer:
PyScripts
Note: This Question is unanswered, help us to find answer for this one
Check Answer
624. When looping over a dictionary, entries are found in which order? for k,v in mydict.items(): print k,v
unsorted
sorted in order of the key
in the order they were added to the dictionary
Last In, First Out
sorted in order of the value
Note: This Question is unanswered, help us to find answer for this one
Check Answer
625. What does range(6)[::2] return?
[2,4,6]
[0,1]
SyntaxError
[5,6]
[0,2,4]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
626. Assume myList = [1, 2, 3, 4] What line of code will print myList in reverse?
print myList[-1]
print myList[::-1]
print myList.sort(reverse=True)
print myList.tail()
Answer
Correct Answer:
print myList[::-1]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
627. What is the result of the following expression: print((1, 2, 3) < (1, 2, 4))?
True.
This expression will result in a syntax error.
False.
None.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
628. In Python 3.x, does 3/2 == 3.0/2.0?
Always.
Never.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
629. Which of the following is the correct import statement for the
from sys import exists
from dir import exists
from os import exists
from os.path import exists
Answer
Correct Answer:
from os.path import exists
Note: This Question is unanswered, help us to find answer for this one
Check Answer
630. Which of these should you include in order to pass variables to a script?
from sys import args
from sys import getarg
from system import argv
from sys import argv
Answer
Correct Answer:
from sys import argv
Note: This Question is unanswered, help us to find answer for this one
Check Answer
631. How would you convert the string below to title case and remove all heading/trailing spaces ? myStr = ' ThIs iS a samPle String. '
myStr.title().strip()
myStr.to_title().strip()
title.strip(myStr)
title(myStr).strip()
myStr.striptitle()
Answer
Correct Answer:
myStr.title().strip()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
632. What will typing the following at the Python interpreter produce? ['A','B','C','D','E','F'] + 'G'
['A','B','C','D','E','F','G']
['G','A','B','C','D','E','F']
'ABCDEFG'
TypeError exception
Answer
Correct Answer:
TypeError exception
Note: This Question is unanswered, help us to find answer for this one
Check Answer
633. Which Python string formatting example is correct?
"{0}".format("Python!")
"%s" & "Python!"
print("%s", "Python!")
Answer
Correct Answer:
"{0}".format("Python!")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
634. Python comes with a UI Toolkit in its standard library. This toolkit is:
GTK
Tkinter
Winforms
QT
Note: This Question is unanswered, help us to find answer for this one
Check Answer
635. The with keyword allows you to:
Create a Pointer
Assign a Value to a Variable
Invoke a Context Manager
Answer
Correct Answer:
Invoke a Context Manager
Note: This Question is unanswered, help us to find answer for this one
Check Answer
636. In order to create a string representation of a datetime object, you would use:
The datetime's strptime
The datetime's strftime
Answer
Correct Answer:
The datetime's strftime
Note: This Question is unanswered, help us to find answer for this one
Check Answer
637. When running a python script what is sys.argv[0] equal to?
The last argument passed to the script
The name of the script that was executed
The first argument passed to the script
Answer
Correct Answer:
The name of the script that was executed
Note: This Question is unanswered, help us to find answer for this one
Check Answer
638. Which of the following statements will output the following line, exactly as shown: python is fun\n
print @"python is fun\n"
print r"python is fun\n"
print 'python is fun\n'
print "python is fun\n"
str = 'python is fun\n'; print str
Answer
Correct Answer:
print r"python is fun\n"
Note: This Question is unanswered, help us to find answer for this one
Check Answer
639. What is returned by: ("123")[0]
("123")
None and the system generates an error (exception)
'123'
'1'
None
Note: This Question is unanswered, help us to find answer for this one
Check Answer
640. What is the result of eval("7"), string.atoi("4"), int("7") ?
(7, 4, 7)
(7, 4, 7.0)
("7", 4, 7)
("7", 4, 7.0)
Answer
Correct Answer:
(7, 4, 7)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
641. Which of the following is not an interface for a web server to communicate with a Python program?
fcgi
wsgi
cgi
webcat
Note: This Question is unanswered, help us to find answer for this one
Check Answer
642. What kind of language is Python?
Logical
Functional
Procedural
Multiparadigm
Answer
Correct Answer:
Multiparadigm
Note: This Question is unanswered, help us to find answer for this one
Check Answer
643. What will typing "Python's great' at the Python interpreter produce?
Python\'s great
Python\\'s great
Python's great
Python is great
Answer
Correct Answer:
Python\'s great Python's great
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Check Answer
644. What will typing the following at the Python interpreter produce? s1 = "Good" ; s2 = "Morning" ; s1 s2
SyntaxError exception
GoodMorning
'Good Morning'
'GoodMorning'
Answer
Correct Answer:
SyntaxError exception
Note: This Question is unanswered, help us to find answer for this one
Check Answer
645. What is the difference between the regular expression functions match and search?
search looks for matches only at the start of its input, match finds strings anywhere in the input.
match looks for matches only at the start of its input, search finds strings anywhere in the input.
These functions are the same.
There is no function search in a regular expression module.
Answer
Correct Answer:
match looks for matches only at the start of its input, search finds strings anywhere in the input.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
646. Given the expression monty = ('cave', 'of', 'arghhh'). Which of the following statments about this expression is true?
You can add "wizard tim" to monty using monty.extend("wizard tim").
'monty' points to an object that is immutable once declared.
'monty' is equivalent to the string "cave of arghhh".
monty.pop() will return "arghhh" and remove it from monty.
Answer
Correct Answer:
'monty' points to an object that is immutable once declared.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
647. What does PEP stand for?
Python Echoes Python
Python Engagement Pattern
Python Enhancement Proposal
Particularly Egregious Practices
Answer
Correct Answer:
Python Enhancement Proposal
Note: This Question is unanswered, help us to find answer for this one
Check Answer
648. Assume myDict = {'name': 'Foo', 'surname': 'Bar'} How would you check for the presence of the 'name' key in myDict ?
has_attribute(myDict, 'name')
'name' in myDict
hasattr(myDict, 'name')
has_attribute('name', myDict)
has_attribute(name, myDict)
Answer
Correct Answer:
'name' in myDict
Note: This Question is unanswered, help us to find answer for this one
Check Answer
649. Which of these expressions produce the same results in Python 2.x? 5/3 5.0/3.0 5.0/3
All results are different.
5 / 3 and 5.0 / 3
All results are the same.
5.0 / 3.0 and 5.0 / 3
5.0 / 3.0 and 5 / 3
Answer
Correct Answer:
5.0 / 3.0 and 5.0 / 3
Note: This Question is unanswered, help us to find answer for this one
Check Answer
650. In which of the following may a continue statement occur?
Function definitions, for and while loops, and finally clauses.
For and while loops and finally clauses.
For and while loops.
Class definitions, function definitions, and for and while loops.
Functions definitions and for and while loops.
Answer
Correct Answer:
For and while loops.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
651. If d = set( [ 0, 0, 1, 2, 2, 3, 4] ), what is the value of len(d) ?
8
4
5
6
7
Note: This Question is unanswered, help us to find answer for this one
Check Answer
652. 'chr' is the inverse of:
'ord'
'id'
'bin'
'int'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
653. What will the following print? a = [1,2,3] b = a a[-2] = 0 print(b)
[1,0,3]
[1,2,0]
[0,2,3]
[1,2,3]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
654. Which of these will obtain a list of the distinct values in a list?
uniques = list(x | x not in list_[_:])
uniques = list(set(list_))
uniques = list(list_)
uniques = list_.distinct()
Answer
Correct Answer:
uniques = list(set(list_))
Note: This Question is unanswered, help us to find answer for this one
Check Answer
655. What part of an if, elif, else statement is optional?
elif, else
else
elif
All parts are mandatory.
Answer
Correct Answer:
elif, else
Note: This Question is unanswered, help us to find answer for this one
Check Answer
656. What value will be stored in a variable arr after the expression arr = range(0, 6, 2) is executed?
[0, 2, 4, 6]
[0, 1, 2, 3, 4, 5, 6]
[0, 2, 4]
[2, 3, 4, 5]
Answer
Correct Answer:
[0, 2, 4]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
657. Given a dictionary 'unordered', which of these will sort the dictionary in descending order?
unordered.sort()
Dictionaries cannot be ordered.
unordered.sort("descending")
unordered.sort(descending)
Answer
Correct Answer:
Dictionaries cannot be ordered.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
658. What function is used to list the contents of a directory or a folder?
On Windows computers win.listdir, on Unix computers unix.listdir, on Macs mac.listdir
os.dir
os.foldercontents
os.listdir
Answer
Correct Answer:
os.listdir
Note: This Question is unanswered, help us to find answer for this one
Check Answer
659. What will be the value of the element a[0] after executing this set of commands? a=[1,2,3] b=a b[0]=11
11
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
660. what would be an answer of the code below: a = len('aa') switch a: case 1: print 2 break case 2: print 1 break default: print 0
nothing
no switch in python
case 2 and default - 1 and 0
case 2 - 1
Answer
Correct Answer:
no switch in python
Note: This Question is unanswered, help us to find answer for this one
Check Answer
661. What is the basic difference between theses two operations in 're' module: match() and search()?
re.search() operation checks for a match anywhere in the string. re.match() operation checks for a match only at the begining of the string.
The only difference is that re.search() has much more parameters than re.match()
The only difference is that re.match() has much more parameters than re.search()
There is no difference between the two operations.
re.search() operation checks for a match only at the begining of the string. re.match() operation checks for a match anywhere in the string.
Answer
Correct Answer:
re.search() operation checks for a match anywhere in the string. re.match() operation checks for a match only at the begining of the string.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
662. Which of these list declarations will result in error?
None of these
l = [1, 2, "four"]
l = [1, 2, 4, ]
l = [1, 2, 4]
Answer
Correct Answer:
None of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
663. You need to run two applications which have conflicting dependencies. What Python tool would you use to solve this problem?
there is no simple way to solve this problem using Python
virtualenv
celery
aptitude
appengine
Answer
Correct Answer:
virtualenv
Note: This Question is unanswered, help us to find answer for this one
Check Answer
664. After executing the following statements, what is the value of var? var = "dlrow olleh" var = var[::-1]
The interpreter will crash
'hello world'
Syntax Error
Answer
Correct Answer:
'hello world'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
665. Which of the following is true about (1,2,3,)
It is equivalent to 1,2,3
It represents an immutable object
It is equivalent to [1,2,3,]
It is an invalid expression
Answer
Correct Answer:
It represents an immutable object
Note: This Question is unanswered, help us to find answer for this one
Check Answer
666. What is returned by the following expression: ("123",)[0]
None
'123'
('123')
None and the system generates an error (exception)
'1'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
667. Suppose a= [1,2,3]. What will be the value of 'a' after executing this command, a=a*3 ?
Lists are Immutable. So, this will result in an error message.
[3,6,9]
None
[1,2,3,1,2,3,1,2,3]
Answer
Correct Answer:
[1,2,3,1,2,3,1,2,3]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
668. What standard library module is used for manipulating path names?
pathname
sys.path
stdpath
os.path
paths
Note: This Question is unanswered, help us to find answer for this one
Check Answer
669. True or False: Python has private instance variables.
True when prefixed with the private keyword.
False, but convention states that variable names starting with underscores should be treated as non-public.
True. All variables are private instance variables.
Only in "private" mode.
Answer
Correct Answer:
False, but convention states that variable names starting with underscores should be treated as non-public.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
670. What is delegation?
An object oriented technique to implement a method by calling another method instead.
Applying a function to a list of lists.
Chaining together several function outputs.
Passing the output of one function to another function.
Answer
Correct Answer:
An object oriented technique to implement a method by calling another method instead.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
671. If somewhere in a script is the statement f.close(), which of the following may have come before it?
f.open("tmp.tmp")
open("tmp.tmp")
none are correct
f=open("tmp.tmp")
Answer
Correct Answer:
f=open("tmp.tmp")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
672. How can you define a tuple having one element?
(1,)
(1)
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
673. What is a 'docstring'?
Any string literal in python code is often referred to as a 'docstring'.
Documentation found on python's official websites and tutorials describing parts of the standard library.
A string literal that occurs as the first statement in a module, function, class, or method definition that serves to describe it's function.
A library that's used to automatically generate documentation from function definitions.
Answer
Correct Answer:
A string literal that occurs as the first statement in a module, function, class, or method definition that serves to describe it's function.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
674. How can one convert [1,2,3] to myFile.txt' exists?
[1, 2, 3].merge()
' - '.merge([1,2,3])
' - '.join([1,2,3])
merge([1,2,3], ' - ')
[1, 2, 3].merge(' - ')
Answer
Correct Answer:
' - '.join([1,2,3])
Note: This Question is unanswered, help us to find answer for this one
Check Answer
675. The md5 and sha modules have been deprecated in favor of which module?
hash
hmac
hasher
hashlib
libhash
Note: This Question is unanswered, help us to find answer for this one
Check Answer
676. Python standard library comes with which RDMS library?
oracle
postgresql
mysql
sqlite
Note: This Question is unanswered, help us to find answer for this one
Check Answer
677. The built in Python mapping type is called
hash
dict
list
set
Note: This Question is unanswered, help us to find answer for this one
Check Answer
678. What does the spawn family of functions do?
There are no such functions in Python.
These functions allow a Python program to stop another process.
These functions allow a Python program to stop the current process.
These functions allow a Python program to start another process.
Answer
Correct Answer:
These functions allow a Python program to start another process.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
679. If the body of a function func consists of only one statement pass, what will be the output of the expression print func()?
Empty string
0
None
This expression will result in a syntax error
Note: This Question is unanswered, help us to find answer for this one
Check Answer
680. When do you use strings in triple quotes?
They are used for strings containing Unicode symbols.
Strings in triple quotes can span multiple lines without escaping newlines.
(all of these)
They are used for strings containing regular expressions.
Answer
Correct Answer:
Strings in triple quotes can span multiple lines without escaping newlines.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
681. What does the following code do sys.path.append('/usr/local') ?
Changes the location where subprocesses are searched for after they are launched.
Changes the location from which the Python executable is run.
Adds a new directory to search for imported Python modules
Changes the location where Python binaries are stored.
Changes the current working directory.
Answer
Correct Answer:
Adds a new directory to search for imported Python modules
Note: This Question is unanswered, help us to find answer for this one
Check Answer
682. What are decorators?
A way of applying transformations to a function or method definition using higher-order functions.
Strings printed to standard out in the intermediate stages of processing.
Detailed comments written in the lines directly preceding definitions.
Certain classes of identifiers (besides keywords) that have special meanings.
Answer
Correct Answer:
A way of applying transformations to a function or method definition using higher-order functions.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
683. What is the syntax of assertions in Python?
assert Expression[, Arguments]
test Expression[, Arguments]
check Expression[, Arguments]
Any statement in which only boolean operations are used.
Answer
Correct Answer:
assert Expression[, Arguments]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
684. What kinds of variables can be used in Python programs?
Floats only.
Integers only.
Integers and floats.
Integers, longs, floats and imaginary numbers.
Answer
Correct Answer:
Integers, longs, floats and imaginary numbers.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
685. What kind of functions are created with a lambda expression?
There is no lambda expression in Python.
Boolean
Anonymous
Precompiled
Answer
Correct Answer:
Anonymous
Note: This Question is unanswered, help us to find answer for this one
Check Answer
686. How would you check if the file 'myFile.txt' exists?
path_exists(
file_exists(
os.exists(
os.path.exists(
Answer
Correct Answer:
os.path.exists(
Note: This Question is unanswered, help us to find answer for this one
Check Answer
687. Which of these structures cannot contain duplicates?
A Set
A Sequence
A List
A Tuple
Note: This Question is unanswered, help us to find answer for this one
Check Answer
688. What is the purpose of the map function?
To integrate geographical data (such as Google Maps) in Python programs.
To construct a directory of a Python package.
To take a list and remove elements based on some criteria.
To perform a specific action on each element of a list without writing a loop.
Answer
Correct Answer:
To perform a specific action on each element of a list without writing a loop.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
689. What is the result of string.lower('RR')?
RR'
'lower'
an AttributeError exception
rr
'rr'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
690. What would be the result of: print not (True or False) ?
TRUE
1
0
False
Note: This Question is unanswered, help us to find answer for this one
Check Answer
691. The 'distutils' module provides
the packaging tools for Python
utility functions for calculating distance
utility functions for higher order math functions.
Answer
Correct Answer:
the packaging tools for Python
Note: This Question is unanswered, help us to find answer for this one
Check Answer
692. What is the correct form for the first line of the switch operator?
There is no switch operator in Python
switch?
switch
switch:
Answer
Correct Answer:
There is no switch operator in Python
Note: This Question is unanswered, help us to find answer for this one
Check Answer
693. What syntax do you use when you create a subclass of an existing class?
You cannot extend classes in Python
SubclassName is subclass of BasicClassName
class SubclassName(BasicClassName):
class BasicClassName(SubclassName):
Answer
Correct Answer:
class SubclassName(BasicClassName):
Note: This Question is unanswered, help us to find answer for this one
Check Answer
694. Which example would return "Python Supremacy"?
"Python _".find("_", "Supremacy")
"Python _".replace("_", "Supremacy")
"Python _".substitute("_", "Supremacy")
Answer
Correct Answer:
"Python _".replace("_", "Supremacy")
Note: This Question is unanswered, help us to find answer for this one
Check Answer
695. What is a package?
Any Python program which imports external modules.
All Python programs that are available on the computer.
A folder with module files that can be imported together.
Any folder with Python source code files in it.
Answer
Correct Answer:
A folder with module files that can be imported together.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
696. What does the expression "(lambda x: x + 3)(1)" return?
'lambda lambda lambda'
An anonymous function.
A syntax error.
13
4
Note: This Question is unanswered, help us to find answer for this one
Check Answer
697. Is it possible to swap values of variables a and b by using the expression 'a, b = b, a' ?
Yes, but only for string variables
Yes, but only for numeric variables
It is always possible.
No.
Answer
Correct Answer:
It is always possible.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
698. If you want to enter accented characters, what is put in front of the string the character?
d
g
G
u
Note: This Question is unanswered, help us to find answer for this one
Check Answer
699. How can you open a binary file named dino?
fopen 'dino', 'r'
open('dino', 'r')
open 'dino', 'r'
open('dino', 'rb')
Answer
Correct Answer:
open('dino', 'rb')
Note: This Question is unanswered, help us to find answer for this one
Check Answer
700. Which of these two operations can be applied to a string: +, * ?
Both of them.
Only +
Only *
Neither.
Answer
Correct Answer:
Both of them.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
701. Why might a Python module have the following code at the end: if __name__ == '__main__'?
Code that is written after this statement is executed only when the module is used directly.
Code that is written after this statement is ignored by the interpreter, so comments are usually added after it.
Some of the viruses that infect Python files do not affect modules with such a statement.
This code prevents a module from being executed directly.
Answer
Correct Answer:
Code that is written after this statement is executed only when the module is used directly.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
702. Which of the following is not a valid data type in Python?
str
float
int
double
bool
Note: This Question is unanswered, help us to find answer for this one
Check Answer
703. How can each line of an already-opened text file be printed?
cat file_
for line in file_: print line
while True: if not line: break line = file_.readline()
print file_
Answer
Correct Answer:
for line in file_: print line
Note: This Question is unanswered, help us to find answer for this one
Check Answer
704. Which keywords can be used to define a function?
def, lambda
def, defun
def, letrec
def, proc
def, import
Answer
Correct Answer:
def, lambda
Note: This Question is unanswered, help us to find answer for this one
Check Answer
705. How would you assign the last element of a list to the variable 'x' without modifying the list?
x = last(aList)
x = aList[-1]
x = aList.pop()
x = aList.last()
Answer
Correct Answer:
x = aList[-1]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
706. How is a default value to a function's parameter provided?
It is impossible to provide a default value to a function's parameter.
By writing the desired value in parentheses after the parameter's name.
By writing the desired value in curly brackets after the parameter's name.
By writing an equal sign after the parameter's name and then the desired value.
Answer
Correct Answer:
By writing an equal sign after the parameter's name and then the desired value.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
707. By convention, where are internal variables set in a Python class?
the __class__ function
the __init__ function
global variables
the init function
Answer
Correct Answer:
the __init__ function
Note: This Question is unanswered, help us to find answer for this one
Check Answer
708. Assume myList = [1, 2, 3, 4, 5] and myVar = 3 How would you check if myVar is contained in myList?
myList.has_item(myVar)
myList.contains(myVar)
myVar.exists(myList)
myVar in myList
myVar.in(myList)
Answer
Correct Answer:
myVar in myList
Note: This Question is unanswered, help us to find answer for this one
Check Answer
709. Given the following assignment: s = ('xxx', 'abcxxxabc', 'xyx', 'abc', 'x.x', 'axa', 'axxxxa', 'axxya'), what is the result of the expression filter ((lambda s: re.search(r'xxx', s)), s)?
This expression will result in a syntax error.
('x.x')
('xxx', 'abcxxxabc', 'axxxxa')
('xxx')
Answer
Correct Answer:
('xxx', 'abcxxxabc', 'axxxxa')
Note: This Question is unanswered, help us to find answer for this one
Check Answer
710. What will typing the following at the Python interpreter produce? sequence = ['A','B','C','D','E','F'] ; sequence[-6]
'F'
'B'
IndexError exception
'A'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
711. What is used to read the next line in a file up to the '\n'?
open('file').readline()
open('file').read('\n')
open('file').read()
open('file').readlines()
Answer
Correct Answer:
open('file').readline()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
712. What does the pass statement do?
Nothing. It can be used when a statement is needed syntactically.
Jumps to the top of the closest enclosing loop.
There is no such statement in Python.
It passes control flow of the program to the debugger.
It is a function which asks the user to enter a password.
Answer
Correct Answer:
Nothing. It can be used when a statement is needed syntactically.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
713. If variables a and b are initialized using an assignment (a, b) = (4, 6), what value will be stored in a variable c by using a statement c = eval("a*b")?
444444
This statement will result in a syntax error.
"a*b"
24
Note: This Question is unanswered, help us to find answer for this one
Check Answer
714. True or False; you can't create async program in python
False
True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
715. What will typing the following at the Python interpreter produce? >>> url = 'http://docs.python.org' >>> url[-4:]
'.org'
IndexError: string index out of range
'http'
'python.org'
'docs'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
716. Which of these lines will return 125?
Math.pow( 5, 3)
5 ^ 3
pow( "5 ^ 3")
5 ** 3
Note: This Question is unanswered, help us to find answer for this one
Check Answer
717. What will happen if you try to add an integer to a long number?
The result will be an integer.
The result of this operation is undefined.
The result will be a long number.
Python will warn you about a type mismatch and ask if you want to convert an integer to a long.
This operation will result in an overflow error.
Answer
Correct Answer:
The result will be a long number.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
718. What is the main difference between a tuple and a list?
Tuples are created with parentheses and lists are create with square brackets.
Tuples are created with square brackets and lists are create with square with parentheses.
Tuples can contain no more than 16 elements, lists can contain more than that.
Lists are changeable sequences of data, while tuples are not changeable.
Answer
Correct Answer:
Lists are changeable sequences of data, while tuples are not changeable.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
719. True or False? you can create Android programs with Python.
True
False
Note: This Question is unanswered, help us to find answer for this one
Check Answer
720. What is the statement that can be used in Python if a statement is required syntactically but the program requires no action?
pass
return
yield
continue
break
Note: This Question is unanswered, help us to find answer for this one
Check Answer
721. What is a string in Python?
An object which is a sequence of characters
Any text put in double-quotes
The same thing as a statement, just an argument
A line of source code
Answer
Correct Answer:
An object which is a sequence of characters
Note: This Question is unanswered, help us to find answer for this one
Check Answer
722. Is it possible to catch AssertionError exceptions?
Yes
Yes, but only when not in Python's interactive shell
Yes, but only in Python's interactive shell
No
Note: This Question is unanswered, help us to find answer for this one
Check Answer
723. What will be result of 3/2 in Python 2.x?
2
1.5
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
724. According to PEP8 python programs should generally be indented with:
2 spaces
8 spaces
1 tab
4 spaces
Note: This Question is unanswered, help us to find answer for this one
Check Answer
725. What is the type of the expression [" "]?
array
string
tuple
list
Note: This Question is unanswered, help us to find answer for this one
Check Answer
726. Does the elif statement require a logical expression?
No, there is no elif statement in Python
Yes
No
Yes, unless it is used in place of an else statement
Note: This Question is unanswered, help us to find answer for this one
Check Answer
727. What is the name of a feature invoked by the following: "This is a string"[3:9]
Multi-indexing
Pieces
Pathfinding
Slices
Note: This Question is unanswered, help us to find answer for this one
Check Answer
728. Assume dictionary mydict = {'foo': 'Hello', 'bar': 'World!'} Which of the below would change the value of foo to 'Goodbye' ?
mydict.update('foo', 'Goodbye')
mydict[foo] = 'Goodbye'
mydict.foo.update('Goodbye')
mydict['foo'] = 'Goodbye'
mydict.foo = 'Goodbye'
Answer
Correct Answer:
mydict['foo'] = 'Goodbye'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
729. What does a function definition header end with?
:
nothing
end of line
Note: This Question is unanswered, help us to find answer for this one
Check Answer
730. What is a fundamental difference between a list and a tuple?
Lists have no length limit.
Lists can be nested, tuples not.
Lists can be mutated, while tuples cannot.
Lists cannot be mutated, while tuples can.
Only list can be subclassed.
Answer
Correct Answer:
Lists can be mutated, while tuples cannot.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
731. What function is used to convert integer numbers to floats?
floatize
float
int_to_float
int2float
Note: This Question is unanswered, help us to find answer for this one
Check Answer
732. Given the list "li = ["a", "Sir Robin", "Sir Gawaine", "Sir Not Appearing in this film", "cb", "rabbits"]", what does the following list comprehension return "[item for item in li if len(item) > 2]"?
['Sir Robin', 'Sir Gawaine', 'Sir Not Appearing in this film']
4
['Sir Robin', 'Sir Gawaine', 'Sir Not Appearing in this film', 'rabbits']
['Sir Robin', 'Sir Gawaine', 'Sir Not Appearing in this film', 'cb', 'rabbits']
True
Answer
Correct Answer:
['Sir Robin', 'Sir Gawaine', 'Sir Not Appearing in this film', 'rabbits']
Note: This Question is unanswered, help us to find answer for this one
Check Answer
733. How can the elements in a list be reversed?
list_.flip()
list_ = list_[-1::]
list_.reverse()
list_[-1:-len(a)]
Answer
Correct Answer:
list_.reverse()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
734. The range(n) function returns values from...
0 to n-1
0 to n
n-1 to n
Syntax error: missing arguments
Note: This Question is unanswered, help us to find answer for this one
Check Answer
735. How do you print from 0 to 10 in python?
for i in range(11): print i
for( x = 0; x < 11; x++) printf("%s",x);
while x < 10: print x
for i in range(10): print i
Answer
Correct Answer:
for i in range(11): print i
Note: This Question is unanswered, help us to find answer for this one
Check Answer
736. If i and j are numbers, which statement evaluates to the remainder of i divided by j?
i mod j
i % j
i // j
i / j
Note: This Question is unanswered, help us to find answer for this one
Check Answer
737. Which of these lines properly checks the length of a variable named "l"?
l.len()
len(l)
length(l)
l.length()
Note: This Question is unanswered, help us to find answer for this one
Check Answer
738. What is the value of the variable a after the following statement: a=(1,2,3); a=a[2];
2
None and the system generates an error (exception)
None
1
3
Note: This Question is unanswered, help us to find answer for this one
Check Answer
739. How does one pause the execution of a program for 5 seconds?
import date date.pause(5)
import time time.sleep(5)
import date date.pause(5.0)
Answer
Correct Answer:
import time time.sleep(5)
Note: This Question is unanswered, help us to find answer for this one
Check Answer
740. Which of the following is NOT a valid part of an "if" block?
elseif:
elif:
if:
else:
Note: This Question is unanswered, help us to find answer for this one
Check Answer
741. How would you declare a list x in Python with predefined values of 1, 2 and 3 ?
x = list{'1', '2', '3'}
x = list(1, 2, 3)
x = {'1', '2', '3'}
x = [1, 2, 3]
x = new list (1, 2, 3)
Answer
Correct Answer:
x = [1, 2, 3]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
742. The statement 'a,b = b,a' is a valid way to successfuly switch the values of the variables a and b in Python.
False
True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
743. What is the del statement used for?
To remove a function from a list given its name.
To remove an item from a list given its index.
To delete a file from the file system given its path.
To delete a user if you are a privileged user.
Answer
Correct Answer:
To remove an item from a list given its index.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
744. When defining a class, what controls which parameters that may be passed when the class is instantiated?
There is no way to pass parameters to a class instance.
Specifying those parameters after the class name.
Specifying those parameters in the definition of an __init__ method of the class.
Writing the desired values after the class name when the class instance is created.
Answer
Correct Answer:
Specifying those parameters in the definition of an __init__ method of the class.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
745. Which one of following Internet protocols is supported by Python libraries: HTTP, FTP, SMTP, POP3, IMAP4, NNTP, Telnet?
Only HTTP
Only HTTP, FTP, POP3, IMAP4
None of them
All of them
Answer
Correct Answer:
All of them
Note: This Question is unanswered, help us to find answer for this one
Check Answer
746. How are non-anonymous Python functions declared?
With the "function" keyword.
With the "def" keyword.
With function prototypes declared in header files.
With "do function ... done".
Answer
Correct Answer:
With the "def" keyword.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
747. What operator checks the inequality of two values?
!=
isn't
=/=
><
>=
Note: This Question is unanswered, help us to find answer for this one
Check Answer
748. What is a variable?
A statement which allows you to choose one variant from a given set
A collection of elements, each identified by an index
An object which may contain some data
An object containing data whose value cannot be altered by the program
Answer
Correct Answer:
An object which may contain some data
Note: This Question is unanswered, help us to find answer for this one
Check Answer
749. Which of these will result in an error?
"hello" * 2
"hello" ** 2
len ( "hello" )
"hello" + "hello"
Answer
Correct Answer:
"hello" ** 2
Note: This Question is unanswered, help us to find answer for this one
Check Answer
750. What is a string delimited by?
"
"""
'''
All of these are correct,
'
Answer
Correct Answer:
All of these are correct,
Note: This Question is unanswered, help us to find answer for this one
Check Answer
751. How are comments denoted in Python?
<!-- text -->
# text
// text
/* text */
^^ text ^^
Note: This Question is unanswered, help us to find answer for this one
Check Answer
752. What function do you use to determine the size of a tuple, a list, or a string?
len
length
size
Tuplen for tuples, listlen for lists, strlen for strings
Note: This Question is unanswered, help us to find answer for this one
Check Answer
753. What does the print statement do?
Returns the status of all printers installed on the network.
Evaluates its parameters and writes the resulting objects to standard output.
Allows users to input data.
Prints the source code on the default printer.
Answer
Correct Answer:
Evaluates its parameters and writes the resulting objects to standard output.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
754. What data type is the following: [1, 2, 3] ?
Counter.
List.
Dictionary.
Tuple.
Set.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
755. Is it possible to call a function from within another function?
Yes, but only in the interactive shell.
Yes, but only when the program runs on a remote server.
Yes.
No.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
756. What kind of type system does Python have?
Dynamic.
Inverse.
Loading.
Proportional.
Static.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
757. When opening the Python shell, the prompt you see is
>
#
$
>>>
Note: This Question is unanswered, help us to find answer for this one
Check Answer
758. Which of the following data structures supports the 'in' operator: list, dictionary, set ?
None.
set
list
dictionary
All three.
Answer
Correct Answer:
All three.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
759. What will be the value of a variable x after executing the expression x = y = 1?
This expression will result in a syntax error.
Undefined
0
1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
760. What is the maximum recursion limit in Python?
It's configurable.
100000
100
10000
1000000
Answer
Correct Answer:
It's configurable.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
761. What does the sys module include?
All are correct.
The name of the operating system where your Python code is run.
The largest integer the machine's architecture supports.
The Python interpreter's version number.
Answer
Correct Answer:
All are correct.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
762. What keyword is needed to use an external module?
use
package
external
import
Note: This Question is unanswered, help us to find answer for this one
Check Answer
763. True or False. in python you can run linux command
False
True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
764. True or False: Python holds the current working directory in memory.
False
True
Note: This Question is unanswered, help us to find answer for this one
Check Answer
765. Which Python implementation is best for testing Java code?
CPython
IronPython
Jython
PyPy
Note: This Question is unanswered, help us to find answer for this one
Check Answer
766. How does one print the string "fred" on a line by itself in Python 2.x?
print 'fred'
println('fred')
cout << "fred" << endl;
write('fred')
Answer
Correct Answer:
print 'fred'
Note: This Question is unanswered, help us to find answer for this one
Check Answer
767. What character is used to denote the beginning of a comment?
//
{
/*
#
Note: This Question is unanswered, help us to find answer for this one
Check Answer
768. What will be printed as the result of: animals = ['bear', 'tiger', 'penguin', 'zebra'] print animals[2] ?
bear
tiger
penguin
zebra
Note: This Question is unanswered, help us to find answer for this one
Check Answer
769. If you want a function you define to return "a", what should be put on the last line of the function (correctly indented)?
"a"
ret("a")
return "a"
a
Answer
Correct Answer:
return "a"
Note: This Question is unanswered, help us to find answer for this one
Check Answer
770. What is the purpose of an 'if' statement?
Repeatedly execute a block of code
Conditionally execute a block of code
Execute code from more than one place in a program
Answer
Correct Answer:
Conditionally execute a block of code
Note: This Question is unanswered, help us to find answer for this one
Check Answer
771. What is the index of the first item in a tuple or list?
0
1
-2,147,483,648
-1
Note: This Question is unanswered, help us to find answer for this one
Check Answer
772. Python files typically have which extension?
py
pl
pt
pie
pil
Note: This Question is unanswered, help us to find answer for this one
Check Answer
773. Python variables are references to objects.
Always
Never
Note: This Question is unanswered, help us to find answer for this one
Check Answer
774. Functions are first-class objects in Python.
Always
Never
Note: This Question is unanswered, help us to find answer for this one
Check Answer
775. Which of these values equates to True?
()
None of these
""
{}
Answer
Correct Answer:
None of these
Note: This Question is unanswered, help us to find answer for this one
Check Answer
776. What will typing the following at the Python interpreter produce? [3]*3
'9'
[9]
'333'
[3, 3, 3]
Answer
Correct Answer:
[3, 3, 3]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
777. What is the difference between using single quotes and double quotes in Python strings?
Single quotes are for short strings. Double quotes are for long strings.
There is no difference.
Double quotes are for constants. Single quotes are for variables.
In Python you can use only single quotes.
Answer
Correct Answer:
There is no difference.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
778. What is the exponentiation (power) operator?
**
^
Both are correct.
None are correct.
Note: This Question is unanswered, help us to find answer for this one
Check Answer
779. From which module can a user import classes and methods to work with regular expressions?
sys
re
regularexpressions
regexp
Note: This Question is unanswered, help us to find answer for this one
Check Answer
780. What would be printed? x = [[1, 2], [3, 4], [5, 6]] x = [x for x in x for x in x] print x
[[1, 2], [1, 2], [1, 2]]
Compilation error
[1, 2, 3, 4, 5, 6]
[6, 6, 6, 6, 6, 6]
[[1, 2], [3, 4], [5, 6]]
Answer
Correct Answer:
[1, 2, 3, 4, 5, 6]
Note: This Question is unanswered, help us to find answer for this one
Check Answer
781. What is a correct term for the following piece of Python syntax: 3 + 4
A statement.
A lambda.
A closure.
A suite.
An expression.
Answer
Correct Answer:
An expression.
Note: This Question is unanswered, help us to find answer for this one
Check Answer