Core Module - 04
Core Module - 04
1. Python Programming Language was developed by? 6. Is Python a cross platform language?
A. Wick van Rossum A. False
B. Rasmus Lerdorf B. True
C. Niene Stom C. Can't say
D. Guido van Rossum D. None of the above
ANSWER: D ANSWER: B
2. Identify the correct option. 7. Which of the following functions can help us to find
A. Python code is only compiled the version of python that we are currently working
on?
B. Python code is neither compiled nor interpreted
A. sys.version
C. Python code is both compiled and interpreted
B. sys.version(0)
D. Python code is only interpreted
C. sys.version()
ANSWER: C
D. sys.version(3)
ANSWER: A
3. Python Programming Language was developed by?
A. Wick van Rossum
8. In python, what does pip stand?
B. Rasmus Lerdorf
A. Pip Installs Python
C. Niene Stom
B. Preferred Installer Program
D. Guido van Rossum
C. Pip Installs Packages
ANSWER: D
D. All of the mentioned
ANSWER: B
4. Identify the correct option.
A. Python code is only compiled
9. Identify the correct definition for packages in Python?
B. Python code is neither compiled nor interpreted
A. A set of main modules
C. Python code is both compiled and interpreted
B. A set of programs making use of Python modules
D. Python code is only interpreted
C. A number of files containing Python definitions
ANSWER: C and statements
D. A folder of python modules
5. In Python, all keywords are _________ ANSWER: D
A. Capitalized
B. lower case 10. Is Python a dynamically typed language?
C. UPPER CASE A. False
D. None of the mentioned B. True
ANSWER: D C. Can't say
D. None of the above
ANSWER: B
Page | 1
11. In Python, what are the two main types of functions? 16. Operators with the same precedence are evaluated in
which manner?
A. System function
A. Can’t say
B. Custom function
B. Right to Left
C. User function
C. Left to Right
D. Built-in function & User defined function
D. None of the mentioned
ANSWER: D
ANSWER: C
Page | 2
20. What is the average value of the following Python 24. Identify which of the following operators has its
code snippet? associativity from right to left?
>>>grade1 = 60 A. **
>>>grade2 = 90 B. //
>>>average = (grade1 + grade2) / 2 C. %
A. 75.0 D. +
B. 85.1 ANSWER: A
C. 95.0
D. 95.1 25. What is the value of the following expression?
ANSWER: A 3+4.00, 3**4.0
A. (7.0, 81.0)
21. What does 5 ^ 4 evaluate to? B. (6.00, 16.00)
A. 31 C. (6, 16)
B. 12 D. (6.00, 16.0)
C. 0.75 ANSWER: A
D. 1
ANSWER: D 26. Identify which of the following is the truncation
division operator?
A. /
22. What will be the value of the following Python
expression? B. //
8+3%5 C. %
A. 5 D. |
B. 11 ANSWER: B
C. 2
D. 0 27. Evaluate the value of the following expression?
ANSWER: B 16/4/2, 16/(4/2)
A. (2.0, 8.0)
23. Evaluate the expression given below if a = 17 and b = B. (1.0, 1.0)
16.
C. (4.0. 1.0)
a % b // a
D. (4.0, 4.0)
A. 0.0
ANSWER: A
B. 0
C. 1.0
D. 1
ANSWER: B
Page | 3
28. Evaluate the value of the following expression? 32. Evaluate the value of the following Python
expression?
float(32//3+2/2)
7+2**5//10
A. 8
A. 5
B. 11.0
B. 10
C. 8.3
C. 77
D. 8.33
D. 0
ANSWER: B
ANSWER: B
Page | 4
35. Evaluate the result of the following Python code? 38. Evaluate the result of the following Python code?
for i in range(4): print("xycdpq".find("cd"))
if i == 4: A. True
break B. 2
else: C. 3
print(i) D. None of the mentioned
else: ANSWER: B
print("Here")
A. 0 1 2 3 Here 39. Evaluate the result of the following Python code?
B. 0 1 2 3 4 5 Here print("aadaddad".find("a"))
C. 0 1 2 3 4 A. 4
D. 1 2 3 4 5 B. 0
ANSWER: A C. Error
D. True
36. Evaluate the result of the following Python code? ANSWER: B
string = "my name is q"
for x in string: 40. Evaluate the result of the following Python code?
print (x, end=", ") print('cd'.isalpha())
A. m, y, , n, a, m, e, , i, s, , q, A. True
B. mynameisq B. False
C. my, name, is, q, C. None
D. error D. Error
ANSWER: A ANSWER: A
37. Which of the following statement prints 41. Evaluate the result of the following Python code
hello\example\hello.txt? snippet?
A. print(“hello\example\hello.txt”) print(''.isdigit())
B. print(“hello\\example\\hello.txt”) A. False
C. print(“hello\”example\”hello.txt”) B. True
D. print(“hello”\example”\hello.txt”) C. None
ANSWER: B D. Error
ANSWER: A
Page | 5
42. Evaluate the result of the following Python code 47. Evaluate the result of the following Python code?
snippet?
>>>t=(1,9,7,3)
print('25'.isnumeric())
>>>t[1:3]
A. True
A. (1, 9)
B. False
B. (1, 9, 7)
C. None
C. (9, 7)
D. Error
D. (9, 7, 3)
ANSWER: A
ANSWER: C
45. Suppose list1 is [9, 5, 25, 2, 3], what is min(list1)? 50. Evaluate the result of the following Python code?
A. 3 >>> x=[(2,4),(1,2),(3,9)]
B. 5 >>> x.sort()
C. 25 >>> x
D. 2 A. [(1, 2), (2, 4), (3, 9)]
ANSWER: D B. [(2,4),(1,2),(3,9)]
C. Error because tuples are immutable
46. Suppose list1 is [3, 5, 9], what is sum(list1)? D. Error, tuple has no sort attribute
A. 1 ANSWER: A
B. 9
C. 17
D. Error
ANSWER: C
Page | 6
51. Evaluate the result of the following Python code 54. Evaluate the result of the following Python code
snippet? snippet?
>>> d = {"annie":40, "peter":45} d = {"jenny":90, "peter":45}
>>> "annie" in d d["jenny"]
A. True A. 90
B. False B. 45
C. None C. “jenny”
D. Error D. “peter”
ANSWER: A ANSWER: A
52. Evaluate the result of the following Python code 55. Evaluate the result of the following Python code?
snippet?
a={5:"A",6:"B",7:"C"}
x1 = {"jenny":40, "peter":45}
a.clear()
x2 = {"jenny":466, "peter":45}
print(a)
x1 == x2
A. None
A. True
B. { None:None, None:None, None:None}
B. False
C. {1:None, 2:None, 3:None}
C. None
D. { }
D. Error
ANSWER: D
ANSWER: B
Page | 7
58. Evaluate the result of the following Python code 61. Evaluate the result of the following Python code?
snippet?
def Maxprint(x, y):
test = {4:'A', 5:'B', 6:'C'}
if x > y:
test = {}
print(x, 'is maximum')
print(len(test))
elif x == y:
A. 0
print(x, 'is equal to', y)
B. None
else:
C. 3
print(y, 'is maximum')
D. An exception is thrown
Maxprint(5, 6)
ANSWER: A
A. 5
B. 6
59. Evaluate the result of the following Python code
C. 6 is maximum
snippet?
D. None of the mentioned
test = {1:'X', 2:'Y', 3:'Z'}
ANSWER: C
del test[1]
test[1] = 'Q'
62. Identify which of the following is a feature of
del test[2]
DocString?
print(len(test))
A. Provide a convenient way of associating
A. 0 documentation with Python modules, functions, classes,
and methods
B. 2
B. All functions should have a docstring
C. Error as the key-value pair of 1:'X' is already
deleted C. All of the mentioned
D. 1 D. Docstrings can be accessed by the __doc__
attribute on objects
ANSWER: B
ANSWER: C
Page | 8
64. Evaluate the result of the following Python code? 67. Identify the current syntax of rename() for a file?
def cube(y): A. rename(()(current_file_name, new_file_name))
return y * y * y B. rename(new_file_name, current_file_name,)
y = cube(2) C. rename(current_file_name, new_file_name)
print x D. none of the mentioned
A. 2 ANSWER: C
B. 4
C. 8 68. Identify the use of truncate() method in file?
D. 20 A. deletes the file size
ANSWER: C B. deletes the content of the file
C. truncates the file size
65. Evaluate the result of the following Python code? D. none of the mentioned
def f1(): ANSWER: C
x=50
print(x) 69. What represents an entity in the real world with its
identity and behaviour.
x=20
A. method
f1()
B. operator
A. Error
C. class
B. 20
D. object
C. 50
ANSWER: D
D. 5020
ANSWER: C
70. What is used to create an object?
A. class
66. Evaluate the result of the following Python code?
B. In-built functions
def san(y):
C. User-defined functions
print(y+1)
D. constructor
y=-2
ANSWER: D
y=4
san(20)
A. 21
B. 10
C. 2
D. 5
ANSWER: A
Page | 9
71. Evaluate the result of the following Python code? 75. Evaluate the result of the following Python code?
class test: class fruits:
def __init__(self,a="Good Morning"): def __init__(self, price):
self.a=a self.price = price
def display(self): obj=fruits(50)
print(self.a) obj.quantity=10
obj=test() obj.bags=2
obj.display() print(obj.quantity+len(obj.__dict__))
A. The program has an error because constructor can’t A. 13
have default arguments
B. 52
B. Nothing is displayed
C. 12
C. “Good Morning” is displayed
D. 60
D. The program has an error display function doesn’t
ANSWER: A
have parameters
ANSWER: C
76. The assignment of more than one function to a
particular operator is _______
72. Purpose of setattr()?
A. Operator overloading
A. access the attribute of the object
B. Operator overriding
B. delete an attribute
C. Operator over-assignment
C. check if an attribute exists or not
D. Operator instance
D. set an attribute
ANSWER: A
ANSWER: D
78. Identify the methods which begin and end with two
74. Purpose of Instantiation in terms of OOP underscore characters called?
terminology?
A. Additional methods
A. Creating an instance of class
B. In-built methods
B. Modifying an instance of class
C. User-defined methods
C. Copying an instance of class
D. Special methods
D. Deleting an instance of class
ANSWER: D
ANSWER: A
Page | 10
79. Identify which of the following statement is wrong 83. Identify when will the else part of try-except-else be
about inheritance? executed?
A. Private members of a class can be inherited and A. when no exception occurs
accessed
B. when an exception occurs
B. The inheriting class is called a subclass
C. always
C. Protected members of a class can be inherited
D. when an exception occurs in to except block
D. Inheritance is one of the features of OOP
ANSWER: A
ANSWER: A
Page | 11
87. Identify which of the following blocks will be 92. Which of these commands are used to print the SQL
executed whether an exception is thrown or not? query of the model in Django?
A. finally A. sqlmigrations
B. else B. makemigrations
C. except C. migrates
D. assert D. showmigration
ANSWER: A ANSWER: A
Page | 12
97. What is Django's staticfiles app used for? 102. Which is Flask default port ?
A. Storing data in cache A. 3000
B. Generating dynamic HTML, B. 2020
C. Handling user authentication, C. 1000
D. Serving static files like images, CSS, and D. 5000
JavaScript,
ANSWER: D
ANSWER: D
99. In which delimiter the conditional statements if-else 104. What construct is used to create anonymous
and endif are enclosed in Django? functions at runtime in python?
A. [%..%] A. lambda
B. None B. anonymous
C. (%..%) C. pi
D. {%..%} D. none of the mentioned
ANSWER: D ANSWER: A
100. Flask is a web development framework created in 105. Identify which of the following is the truncation
which language? division operator in Python?
A. Java A. |
B. Javascript B. %
C. Python C. /
D. C++ D. //
ANSWER: C ANSWER: D
Page | 13
106. Evaluate the result of the following Python code 110. Evaluate the result of the following Python code?
snippet?
x = 'pqrs'
for i in [5, 6, 7, 8][::-1]:
for i in range(len(x)):
print(i, end=' ')
print(i)
A. 8 7 6 5
A. error
B. error
B. 1 2 3 4
C. 5 6 7 8
C. p q r s
D. none of the mentioned
D. 0 1 2 3
ANSWER: A
ANSWER: D
Page | 14
114. Identify the return type of function id? 117. Evaluate the result of the following Python code?
A. bool i=0
B. float while i < 3:
C. int print(i)
D. dict i += 1
ANSWER: C else:
print(0)
115. Evaluate the result of the following Python A. 0 1 2 3 0
expression?
B. error
int(2055)?
C. 0 1 2
A. 2055
D. 0 1 2 0
B. 22
ANSWER: D
C. 25
D. None
118. Evaluate the result of the following Python code?
ANSWER: A
y = "abcdef"
while p in y:
116. Evaluate the result of the following Python code?
print(p, end=" ")
class Truth:
A. a b c d e f
pass
B. abcdef
y=Truth()
C. i i i i i i …
bool(y)
D. error
A. true
ANSWER: D
B. pass
C. false
119. Evaluate the result of the following Python code?
D. error
d = {5: 'a', 6: 'b', 7: 'c'}
ANSWER: A
for i in d:
print(i)
A. 5 6 7
B. a b c
C. 5 a 6 b 7 c
D. none of the mentioned
ANSWER: A
Page | 15
120. Evaluate the result of the following Python code? 123. Evaluate the result of the following Python code
snippet?
d = {5: 'a', 6: 'b', 7: 'c'}
x=2
for x, y in d:
for i in range(x):
print(x, y)
x += 1
A. 5 6 7
print (x)
B. a b c
A. 0 1 2 3 4 …
C. 5 a 6b 7c
B. 3 4
D. none of the mentioned
C. 0 1
ANSWER: D
D. 0 1 2 3
ANSWER: B
121. Evaluate the result of the following Python code?
d = {3, 4, 5}
124. Evaluate the result of the following Python code
for x in d:
snippet?
print(x)
x=3
A. 3 4 5
for i in range(x):
B. {3, 4, 5} {3, 4, 5} {3, 4, 5}
x -= 2
C. error
print (x)
D. none of the mentioned
A. 0 1 2 3 4 …
ANSWER: A
B. 1 -1 -3
C. 0
122. Evaluate the result of the following Python code?
D. error
for x in range(int(2.0)):
ANSWER: B
print(x)
A. 0.0 1.0
125. Evaluate the result of the following Python code
B. 0 1 snippet?
C. error a = [0, 1, 2]
D. none of the mentioned for a[0] in a:
ANSWER: B print(a[0])
A. 0 1 2
B. 0 1
C. 1 1 1
D. error
ANSWER: A
Page | 16
126. Evaluate the result of the following Python 130. Evaluate the result of the following Python
statement? program?
>>>"d"+"ef" def foo(x):
A. d x[0] = ['def']
B. ef x[1] = ['abc']
C. none return id(x)
D. def q = ['abc', 'def']
ANSWER: D print(id(q) == foo(q))
A. Error
127. Evaluate the result of the following Python code B. True
snippet if y=1?
C. False
y<<2
D. None
A. 4
ANSWER: B
B. 2
C. 1
131. Which of the following Python statements will
D. 8 result in the output: 10?
ANSWER: A A = [[1, 2, 3],
[8, 9, 10],
128. Evaluate the values of the following Python [7, 8, 9]]
expressions?
A. A[2][1]
2**(3**2)
B. A[1][2]
(2**3)**2
C. A[3][2]
2**3**2
D. A[2][3]
A. 64, 64, 64
ANSWER: B
B. 512, 512, 512
C. 64, 512, 64
D. 512, 64, 512
ANSWER: D
Page | 17
132. Evaluate the result of the following Python 135. Evaluate the result of the following Python code?
program?
def foo():
x=0
try:
while x < 5:
return 25
print(x)
finally:
x += 1
return 84
if x == 3:
k = foo()
break
print(k)
else:
A. error, there is more than one return statement in a
print(0) single try-finally block
A. error B. 3
B. 0 1 2 0 C. 84
C. 0 1 2 D. 1
D. none of the mentioned ANSWER: C
ANSWER: C
136. Evaluate the result of the following Python code
snippet?
133. Evaluate the result of the following Python
program? def example(a):
def addItem(listParam): a = a + '2'
listParam += [1] a = a*2
mylist = [5,6,7,8,9] return a
addItem(mylist) >>>x=example("hi")
print(len(mylist)) >>>print(x)
A. 6 A. indentation Error
B. 5 B. cannot perform mathematical operation on strings
C. 2 C. hi2
D. 1 D. hi2hi2
ANSWER: A ANSWER: D
134. Evaluate the result of the following Python code? 137. Identify the return value of trunc()?
print("Hi {0[0]} and {0[1]}".format(('there', 'bin'))) A. float
A. Hello ('there', 'bin') and ('foo', 'bin') B. bool
B. Error C. int
C. Hi there and bin D. None
D. None of the mentioned ANSWER: C
ANSWER: C
Page | 18
138. Evaluate the result of print (0.2 + 0.4 == 0.5)? 143. Evaluate the result of the following Python
expression?
A. True
34//6%3, 34//4//2
B. False
A. (2,4)
C. Machine dependent
B. (0,3)
D. Error
C. (1,0)
ANSWER: B
D. (3,1)
ANSWER: A
139. Identify the type of inf?
A. Float
144. What will be the value of y in the following
B. Integer
Python expression, if the result of that expression is
C. Boolean 4?
D. Complex y>>2
ANSWER: A A. 8
B. 4
140. Is the value of the expressions 5/(3*(2-1)) and C. 2
5/3*(2-1) is same?
D. 1
A. True
ANSWER: D
B. False
C. Can't say
145. Evaluate the result of the following Python
D. Error expression if x=10 and y=12?
ANSWER: A x&y
A. b1101
141. What will be the value of x in the following B. 0b1101
Python expression?
C. 8
x = int(53.55+2/2)
D. 1101
A. 53
ANSWER: C
B. 54
C. 22
146. Evaluate the result of the following Python
D. 23 expression?
ANSWER: B 5^12
A. 2
142. Evaluate the value of y in the following Python B. 4
expression?
C. 9
y = 2+8*((3*12)-8)/10
D. 12
A. 30.0
ANSWER: C
B. 30.8
C. 28.4
D. 24.4
ANSWER: D
Page | 19
147. Evaluate the result of the following Python code 150. Evaluate the result of the following Python
if a=5 and b =10? expression if y=22.19?
a=5 print("%5.2f"%y)
b=10 A. 22.1900
a=a^b B. 22.00000
b=a^b C. 22.20
a=a^b D. 22.19
print(a,b) ANSWER: D
A. 10 20
B. 10 10 151. Identify the option that outputs: “There are 4 blue
birds.”
C. 10 5
A. 'There are %g %d birds.' %4 %blue
D. 20 20
B. 'There are %d %s birds.' 4, blue
ANSWER: C
C. 'There are %s %d birds.' %[4, blue]
D. 'There are %d %s birds.' %(4, blue)
148. Evaluate the result of the following Python code?
ANSWER: D
if (8 < 0) and (0 < -8):
print("hello")
152. Evaluate the result of the following Python code?
elif (8 > 0) or False:
x=1
print("good")
while True:
else:
if x%2 == 0:
print("bad")
break
A. error
print(x)
B. hello
x += 2
C. good
A. 1
D. bad
B. 1 2
ANSWER: C
C. 1 2 3 4 5 6 …
D. 1 3 5 7 9 11 …
149. Evaluate the result of the following Python
expression if x=56.236? ANSWER: D
print("%.2f"%x)
A. 56.00
B. 0056.236
C. 56.23
D. 56.24
ANSWER: D
Page | 20
153. Evaluate the result of the following Python code? 156. Evaluate the result of the following Python code?
x=2 x = "pqrst"
while True: i = "p"
if x%3 == 0: while i in x:
break print(i, end = " ")
print(x) A. no output
x += 2 B. i i i i i i …
A. 2 4 6 8 10 … C. p p p p p p …
B. 2 4 D. error
C. 2 3 ANSWER: C
D. error
ANSWER: B 157. Evaluate the result of the following Python code?
x = "pqrst"
154. Evaluate the result of the following Python code? i = "p"
y=0 while i in x:
while y < 5: x = x[:-1]
print(y) print(i, end = " ")
y += 1 A. i i i i i i
if y == 3: B. p p p p p p
break C. a a a
else: D. none of the mentioned
print(0) ANSWER: B
A. 0 1 2 0
B. none of the mentioned 158. Evaluate the result of the following Python code?
C. error x = 'pqrs'
D. 0 1 2 for i in x:
ANSWER: D print(i)
x.upper()
155. Evaluate the result of the following Python code? A. p Q R S
x = "pqrst" B. p q r s
i = "z" C. P Q R S
while i in x: D. error
print(i, end=" ") ANSWER: B
A. pqrst
B. i i i i i i …
C. x x x x x
D. no output
ANSWER: D
Page | 21
159. Evaluate the result of the following Python code? 162. Evaluate the result of the following Python code
snippet?
x = 'efgh'
x = 'pqrs'
for i in x:
for i in range(len(x)):
print(i.upper())
x = 'p'
A. e f g h
print(x)
B. E F G H
A. p
C. e F G H
B. pqrs pqrs pqrs
D. error
C. p p p p
ANSWER: B
D. none of the mentioned
ANSWER: C
160. Evaluate the result of the following Python code?
x = 'pqrs'
163. Evaluate the result of the following Python code?
for i in range(x):
x = 456
print(i)
for i in x:
A. p q r s
print(i)
B. 0 1 2 3
A. 4 5 6
C. error
B. 456
D. none of the mentioned
C. error
ANSWER: C
D. none of the mentioned
ANSWER: C
161. Evaluate the result of the following Python code
snippet?
x = 'pqrs' 164. Evaluate the result of the following Python code?
for i in range(len(x)): d = {10: 'a', 11: 'b', 12: 'c'}
i[x].upper() for x, y in d.items():
print (x) print(x, y)
A. pqrs A. 10 11 12
B. PQRS B. a b c
C. error C. 10 a 11 b 12 c
D. none of the mentioned D. none of the mentioned
ANSWER: C ANSWER: C
Page | 22
165. Evaluate the result of the following Python code? 169. Evaluate the result of the following Python code?
d = {0: 'd', 1: 'e', 2: 'f'} for x in range(float('inf')):
for x in d.values(): print (x)
print(x) A. 0.0 0.1 0.2 0.3 …
A. 0 1 2 B. 0 1 2 3 …
B. d e f C. 0.0 1.0 2.0 3.0 …
C. 0 d 1 e 2 f D. error
D. none of the mentioned ANSWER: D
ANSWER: B
170. Evaluate the result of the following Python code?
166. Evaluate the result of the following Python code? for y in range(int(float('inf'))):
d = {0: 'x', 1: 'y', 2: 'z'} print (y)
for x in d.values(): A. 0.0 0.1 0.2 0.3 …
print(d[x]) B. 0 1 2 3 …
A. 0 1 2 C. 0.0 1.0 2.0 3.0 …
B. a b c D. error
C. 0 x 1 y 2 z ANSWER: D
D. error
ANSWER: D 171. Evaluate the result of the following Python code
snippet?
for x in 'abcd'[::-1]:
167. Evaluate the result of the following Python code?
print (i)
for y in range(0):
A. a b c d
print(y)
B. error
A. 0
C. d c b a
B. no output
D. none of the mentioned
C. error
ANSWER: C
D. none of the mentioned
ANSWER: B
172. Evaluate the result of the following Python code
snippet?
168. Evaluate the result of the following Python code?
for x in '':
for i in range(9.0):
print (x)
print(i)
A. None
A. 0.0 1.0
B. no output
B. 0 1 2
C. error
C. error
D. none of the mentioned
D. none of the mentioned
ANSWER: B
ANSWER: C
Page | 23
176. Evaluate the result of the following Python
statement?
173. Evaluate the result of the following Python code?
>>>print('hi' 'there')
for x in range(10):
A. Error
if x == 5:
B. Output equivalent to print ‘hi\there’
break
C. hithere
else:
D. hi there
print(x)
ANSWER: C
else:
print("Here")
177. Evaluate the result of the following Python code?
A. 0 1 2 3 4 Here
>>>y1="helloworld"
B. 0 1 2 3 4 5 Here
>>>y1[::-1]
C. 1 2 3 4 5
A. world
D. 0 1 2 3 4
B. hello
ANSWER: D
C. dlrowolleh
D. helloworld
174. Evaluate the result of the following Python code?
ANSWER: C
st = "my name is z"
for i in st.split():
178. Evaluate the result of the following Python code?
print (i, end=", ")
>>>ex1 = "snow world"
A. m, y, , n, a, m, e, , i, s, , z,
>>>print("%s" % ex1[4:7])
B. m, y, , n, a, m, e, , i, s, , z
A. sn
C. my, name, is, z,
B. world
D. error
C. wo
ANSWER: C
D. rl
ANSWER: C
175. Evaluate the result of the following Python code
snippet?
a = [0, 1, 2, 3, 4, 5] 179. Evaluate the result of the following Python code?
i = -2 >>>ex1 = "hello world"
for i not in a: >>>ex1[3] = 's'
print(i) >>>print ex1
i += 1 A. hello
A. -2 -1 B. hello world
B. 0 C. Error
C. none of the mentioned D. he world
D. error ANSWER: C
ANSWER: D
Page | 24
180. Provided a string example=”billy” what is the 184. The format function returns ___________ when
output of example.count('l')? applied on a string
A. 2 A. Error
B. 1 B. str
C. None C. bool
D. 0 D. int
ANSWER: A ANSWER: B
181. Evaluate the result of the following Python code? 185. What will be the output of the “hi” +1+2+3?
>>>example = "benny" A. hi123
>>>example.find("e") B. hi
A. Error C. Error
B. -1 D. hi6
C. 1 ANSWER: C
D. 0
ANSWER: C 186. Suppose p=”hello” what will be the return value
of type(p)?
A. int
182. Evaluate the result of the following Python
statement? B. bool
>>>chr(ord('B')) C. str
A. 21 D. String
B. B ANSWER: C
C. a
D. Error 187. In order to return the length of string s what
command do we execute?
ANSWER: B
A. size(s)
B. len(s) only
183. Suppose p is “\t\tHello\n”, what is p.strip()?
C. len(s) OR s.__len__()
A. \t\tHello\n
D. s.size()
B. none
ANSWER: C
C. \t\tHELLO\n
D. Hello
188. Evaluate the result of the following Python code?
ANSWER: D
print("pqrst".center(0))
A. cd
B. pqrst
C. error
D. none of the mentioned
ANSWER: B
Page | 25
189. Evaluate the result of the following Python code? 193. Evaluate the result of the following Python code?
print("pqrst".center(7, 1)) print("ayyzayzazayy".count('ayy', 0, 100))
A. 1abcdef A. 2
B. abcdef1 B. 0
C. abcdef C. 1
D. error D. error
ANSWER: D ANSWER: A
190. Evaluate the result of the following Python code? 194. Evaluate the result of the following Python code?
print("ayyzayzazayy".count('yy')) print('xyz'.encode())
A. 2 A. xyz
B. 0 B. ‘xyz’
C. error C. b’xyz’
D. none of the mentioned D. h’xyz’
ANSWER: A ANSWER: C
191. Evaluate the result of the following Python code? 195. What is the default value of encoding in
encode()?
print("ayyzayzazayy".count('yy', 1))
A. utf-8
A. 2
B. qwerty
B. 0
C. ascii
C. 1
D. utf-16
D. none of the mentioned
ANSWER: A
ANSWER: A
Page | 26
197. Evaluate the result of the following Python code? 201. Evaluate the result of the following Python code
snippet?
print("ayyzayzazayy".endswith("ayy", 0, 2))
print('0xa'.isdigit())
A. 0
A. False
B. 1
B. True
C. True
C. None
D. False
D. Error
ANSWER: D
ANSWER: A
C. None print('forin'.isidentifier())
D. Error A. True
ANSWER: B B. False
C. None
D. Error
ANSWER: A
Page | 27
205. Evaluate the result of the following Python code 209. Evaluate the result of the following Python code?
snippet?
print('Hello!2@#World'.istitle())
print(''''''.isspace())
A. False
A. False
B. True
B. True
C. None
C. None
D. error
D. Error
ANSWER: B
ANSWER: A
Page | 28
213. Evaluate the result of the following Python code
snippet?
217. Evaluate the result of the following Python code
print('xyyxyyxyxyxxy'.replace('xy', '12', 0)) snippet?
A. xyyxyyxyxyx12 print('pq rs tu'.title())
B. 12y12y1212x12 A. pq rs tu
C. 12yxyyxyxyxxy B. error
D. xyyxyyxyxyxxy C. Pq Rs Tu
ANSWER: D D. None of the mentioned
ANSWER: C
214. Evaluate the result of the following Python code
snippet?
218. Evaluate the result of the following Python code
print('xyyxyyxyxyxxy'.replace('xy', '12', 100)) snippet?
A. xyyxyyxyxyxxy print('abcd'.translate({97: 98, 98: 99, 99: 100}))
B. error A. bcdc
C. none of the mentioned B. none of the mentioned
D. 12y12y1212x12 C. error
ANSWER: D D. abcd
ANSWER: B
215. Evaluate the result of the following Python code
snippet?
219. What function do we use to shuffle the list(say
print('abcdefcdghcd'.split('cd', 0)) list1)?
A. error A. random.shuffle(list1)
B. 'abcdefcdghcd' B. shuffle(list1)
C. ['abcdefcdghcd'] C. list1.shuffle()
D. none of the mentioned D. random.shuffleList(list1)
ANSWER: C ANSWER: A
216. Evaluate the result of the following Python code 220. Say list1 is [4, 2, 2, 4, 5, 2, 1, 0], Identify the
snippet? correct syntax for slicing operation?
print('abcdefcdghcd'.split('cd', -1)) A. print(list1[2:])
A. ['ab', 'ef', 'gh'] B. print(list1[:2])
B. ('ab', 'ef', 'gh', ”) C. all of the mentioned
C. ('ab', 'ef', 'gh') D. print(list1[:-2])
D. ['ab', 'ef', 'gh', ”] ANSWER: C
ANSWER: D
Page | 29
221. To insert 8 to the third position in list1, we use 225. Evaluate the result of the following Python code?
which command?
def f(i, values = []):
A. list1.insert(3, 8)
values.append(i)
B. list1.insert(2, 8)
return values
C. list1.add(3, 8)
f(4)
D. list1.append(3, 8)
f(5)
ANSWER: B
v = f(6)
print(v)
222. Identify the command to remove string “hi” from
A. [4] [5] [6]
list1.
B. [4] [4, 5] [4, 5, 6]
A. list1.remove(“hi”)
C. [4, 5, 6]
B. list1.remove(hi)
D. 4 5 6
C. list1.removeAll(“hi”)
ANSWER: C
D. list1.removeOne(“hi”)
ANSWER: A
226. Evaluate the result of the following Python code?
names1 = ['Bob', 'Betty', 'John']
223. Say, listExample is [3, 4, 5, 20, 5, 25, 1, 3],
Identify list1 after listExample.pop(1)? if 'bob' in names1:
A. [3, 4, 5, 20, 5, 25, 1, 3] print(1)
B. [1, 3, 3, 4, 5, 5, 20, 25] else:
C. [1, 3, 4, 5, 20, 5, 25] print(2)
D. [3, 5, 20, 5, 25, 1, 3] A. None
ANSWER: D B. 1
C. 2
224. Say listExample is [3, 4, 5, 20, 5, 25, 1, 3], D. Error
Identify list1 after listExample.pop()? ANSWER: C
A. [3, 5, 20, 5, 25, 1, 3]
B. [1, 3, 3, 4, 5, 5, 20, 25] 227. Evaluate the result of the following Python code?
C. [3, 4, 5, 20, 5, 25, 1] def addItem(listParam):
D. [1, 3, 4, 5, 20, 5, 25] listParam += [1]
ANSWER: C mylist = [31, 32, 33, 34]
addItem(mylist)
print(len(mylist))
A. 1
B. 4
C. 5
D. 8
ANSWER: C
Page | 30
228. Evaluate the result of the following Python code? 231. Evaluate the result of the following Python code?
values = [[3, 4, 5, 1], [33, 6, 1, 2]] a=[100,230,560,[780]]
v = values[0][0] b=list(a)
for lst in values: a[3][0]=950
for element in lst: a[1]=340
if v > element: print(b)
v = element A. [100,340,560,[950]]
print(v) B. [100,230,560,[780]]
A. 6 C. [100,230,560,[950]]
B. 3 D. [100,340,560,[780]]
C. 5 ANSWER: C
D. 1 ----------------------------------------------------------------------
--
ANSWER: D
232. Evaluate the result of the following Python code?
lst=[3,4,6,1,2]
229. Evaluate the result of the following Python code?
lst[1:2]=[7,8]
data = [[[11, 12], [13, 14]], [[15, 16], [17, 18]]]
print(lst)
print(data[1][0][0])
A. [3,4,6,7,8]
A. 11
B. Syntax error
B. 12
C. [3,[7,8],6,1,2]
C. 14
D. [3, 7, 8, 6, 1, 2]
D. 15
ANSWER: D
ANSWER: D
Page | 31
234. Evaluate the result of the following Python code 238. Evaluate the result of the following Python code?
snippet?
A = [[11, 21, 31],
print([i.lower() for i in "HELLO"])
[41, 51, 61],
A. hello
[71, 81, 91]]
B. 'hello'
[A[i][i] for i in range(len(A))]
C. ['hello']
A. [11, 51, 91]
D. ['h', 'e', 'l', 'l', 'o']
B. [31, 51, 71]
ANSWER: D
C. [41, 51, 61]
D. [21, 51, 81]
235. Evaluate the result of the following Python code?
ANSWER: A
s=["pune", "mumbai", "delhi"]
[(w.upper(), len(w)) for w in s]
239. Evaluate the result of the following Python code?
A. [('PUNE', 4), ('MUMBAI', 6), ('DELHI', 5)]
>>>t = (10, 20, 40, 30, 80, 90)
B. ['PUNE', 4, 'MUMBAI', 6, 'DELHI', 5]
>>>[t[i] for i in range(0, len(t), 2)]
C. [PUNE, 4, MUMBAI, 6, DELHI, 5]
A. [20, 30, 90]
D. Error
B. [10, 20, 40, 30, 80, 90]
ANSWER: A
C. [10, 40, 80]
D. (10, 40, 80)
236. Evaluate the result of the following Python code?
ANSWER: C
l=["good", "oh!", "excellent!", "#450"]
print([n for n in l if n.isalpha() or n.isdigit()])
240. Evaluate the result of the following Python code?
A. ['good', 'oh', 'excellent', '450' ]
>>>t1 = (11, 21, 41, 31)
B. ['oh!', 'excellent!', '#450']
>>>t2 = (11, 21, 31, 41)
C. ['good', '#450']
>>>t1 < t2
D. ['good']
A. True
ANSWER: D
B. False
C. Error
237. Evaluate the result of the following Python code?
D. None
A = [[11, 21, 31],
ANSWER: B
[41, 51, 61],
[71, 81, 91]]
[A[row][1] for row in (0, 1, 2)]
A. [71, 81, 91]
B. [41, 51, 61]
C. [21, 51, 81]
D. [11, 41, 71]
ANSWER: C
Page | 32
241. Evaluate the result of the following Python code? 244. Evaluate the result of the following Python code?
>>>my_tuple = (11, 21, 31, 41) >>> a=(0,11,21,31,41)
>>>my_tuple.append( (51, 61, 71) ) >>> b=slice(0,2)
>>>print len(my_tuple) >>> a[b]
A. 1 A. Invalid syntax for slicing
B. 2 B. [0,21]
C. 5 C. (0,11)
D. Error D. (0,21)
ANSWER: D ANSWER: C
Page | 33
247. Evaluate the result of the following Python code? 250. Evaluate the result of the following Python code?
>>> a=(10,20) >>> a=(21,31,11,51)
>>> b=(30,40) >>> a.sort()
>>> c=a+b >>> a
>>> c A. (11,21,31,51)
A. (40,60) B. (21,31,11,51)
B. (10,20,30,40) C. None
C. Error as tuples are immutable D. Error, tuple has no attribute sort
D. None ANSWER: D
ANSWER: B
251. Is the following Python code valid?
248. Evaluate the result of the following Python code? >>> a=(10,20,30)
>>> a,b=60,70 >>> b=a.update(40,)
>>> a,b=b,a A. Yes, a=(10,20,30,40) and b=(10,20,30,40)
>>> a,b B. Yes, a=(10,20,30) and b=(10,20,30,40)
A. (60,70) C. No because tuples are immutable
B. Invalid syntax D. No because wrong syntax for update() method
C. (70,60) ANSWER: C
D. Nothing is printed
ANSWER: C 252. Which of the following is not the correct syntax
for creating a set?
A. set([[11,21],[31,41]])
249. Is the following Python code valid?
B. set([11,21,21,31,41])
>>> a=21,31,41,51
C. set((11,21,31,41))
>>> a
D. {11,21,31,41}
A. Yes, 21 is printed
ANSWER: A
B. Yes, [21,31,41,51] is printed
C. No, too many values to unpack
253. Evaluate the result of the following Python code?
D. Yes, (21,31,41,51) is printed
nums = set([10,10,20,30,30,30,40,40])
ANSWER: D
print(len(nums))
A. 7
B. Error, invalid syntax for formation of set
C. 4
D. 8
ANSWER: C
Page | 34
254. Evaluate the result of the following Python code? 257. Evaluate the result of the following Python code?
>>> a={40,50,60} >>> a={30,40,50}
>>> b={20,80,60} >>> b={50,60,70}
>>> a+b >>> a|b
A. {40,50,60,20,80} A. Invalid operation
B. {40,50,60,20,80,60} B. {30, 40, 50, 60, 70}
C. Error as unsupported operand type for sets C. {50}
D. Error as the duplicate item 6 is present in both sets D. {30,40,60,70}
ANSWER: C ANSWER: B
255. Evaluate the result of the following Python code? 258. Is the following Python code valid?
>>> a={41,51,61} a={31,41,{71,51}}
>>> b={21,81,61} print(a[2][0])
>>> a-b A. Yes, 71 is printed
A. {41,51} B. Error, elements of a set can’t be printed
B. {61} C. Error, subsets aren’t allowed
C. Error as unsupported operand type for set data type D. Yes, {71,51} is printed
D. Error as the duplicate item 6 is present in both sets ANSWER: C
ANSWER: A
259. Identify which of these about a frozenset is not
true?
256. Evaluate the result of the following Python code?
A. Immutable data type
>>> a={51,61,71,81}
B. Allows duplicate values
>>> b={71,81,101,111}
C. Data type with unordered values
>>> a^b
D. Mutable data type
A. {51,61,71,81,101,111}
ANSWER: D
B. {71,81}
C. Error as unsupported operand type of set data type
260. Identify the syntax of the following Python code?
D. {51,61,101,111}
>>> a=frozenset(set([51,61,71]))
ANSWER: D
>>> a
A. {51,61,71}
B. frozenset({51,61,71})
C. Error, not possible to convert set into frozenset
D. Syntax error
ANSWER: B
Page | 35
261. Is the following Python code valid? 264. Evaluate the result of the following Python code?
>>> a=frozenset([50,60,70]) >>> a={11,21,31}
>>> a >>> b=a.copy()
>>> a.add(50) >>> b.add(41)
A. Yes, now a is {50,50,60,70} >>> a
B. No, frozen set is immutable A. {11,21,31}
C. No, invalid syntax for add method B. Error, invalid syntax for add
D. Yes, now a is {50,60,70} C. {11,21,31,41}
ANSWER: B D. Error, copying of sets isn't allowed
ANSWER: A
262. Evaluate the result of the following Python code?
>>> a={31,41,51} 265. Evaluate the result of the following Python code?
>>> a.update([11,21,31]) >>> a={10,20,30}
>>> a >>> b=a.add(40)
A. Error, no method called update for set data type >>> b
B. {11, 21, 31, 41, 51} A. 0
C. Error, list can't be added to set B. {10,20,30,40}
D. Error, duplicate item present in list C. {10,20,30}
ANSWER: B D. Nothing is printed
ANSWER: D
263. Evaluate the result of the following Python code?
>>> a={11,21,31} 266. Evaluate the result of the following Python code?
>>> a.intersection_update({21,31,41,51}) a={10,20,30}
>>> a b={10,20,30}
A. {21,31} c=a.issubset(a)
B. Error, duplicate item present in list print(c)
C. Error, no method called intersection_update for set A. True
data type
B. Error, no method called issubset() exists
D. {11,41,51}
C. Syntax error for issubset() method
ANSWER: A
D. False
ANSWER: A
Page | 36
267. Is the following Python code valid? 271. Evaluate the result of the following Python code
snippet?
a={10,20,30}
a={11:"A",21:"B",31:"C"}
b={10,20,30,40}
print(a.get(11,41))
c=a.issuperset(b)
A. 1
print(c)
B. A
A. False
C. 4
B. True
D. Invalid syntax for get method
C. Syntax error for issuperset() method
ANSWER: B
D. Error, no method called issuperset() exists
ANSWER: A
272. Evaluate the result of the following Python code
snippet?
268. Evaluate the result of the following Python code
a={10:"A",20:"B",30:"C"}
snippet?
print(a.get(50,40))
d = {"ben":40, "peter":45}
A. Error, invalid syntax
print(list(d.keys()))
B. A
A. [“ben”, “peter”]
C. 50
B. [“ben”:40, “peter”:45]
D. 40
C. (“ben”, “peter”)
ANSWER: D
D. (“ben”:40, “peter”:45)
ANSWER: A
273. Evaluate the result of the following Python code?
a={10:"A",20:"B",30:"C"}
269. Which of the following is not a declaration of the
dictionary? b={40:"D",50:"E"}
A. {1: 'C', 2: 'D'} a.update(b)
B. dict([[1,”C”],[2,”D”]]) print(a)
C. {1,”C”,2”D”} A. {10: 'A', 20: 'B', 30: 'C'}
D. { } B. Method update() doesn't exist for dictionaries
ANSWER: C C. {10: 'A', 20: 'B', 30: 'C', 40: 'D', 50: 'E'}
D. {40: 'D', 50: 'E'}
270. Evaluate the result of the following Python code ANSWER: C
snippet?
a={10:"A",20:"B",30:"C"}
for i,j in a.items():
print(i,j,end=" ")
A. 10 A 20 B 30 C
B. 10 20 30
C. A B C
D. 10:”A” 20:”B” 30:”C”
ANSWER: A
Page | 37
274. Evaluate the result of the following Python code? 278. Evaluate the result of the following Python code
snippet?
a={11:"A",21:"B",31:"C"}
a={}
b=a.copy()
a['a']=10
b[21]="D"
a['b']=[20,30,40]
print(a)
print(a)
A. Error, copy() method doesn’t exist for dictionaries
A. Exception is thrown
B. {11: 'A', 21: 'B', 31: 'C'}
B. {'b': [20], 'a': 10}
C. {11: 'A', 21: 'D', 31: 'C'}
C. {'b': [20], 'a': [30]}
D. “None” is printed
D. {'a': 10, 'b': [20, 30, 40]}
ANSWER: B
ANSWER: D
Page | 38
281. For what is delattr(obj,name) used? 285. Evaluate the result of the following Python code?
A. print deleted attribute x[5]
B. set an attribute A. IndexError
C. check if an attribute is deleted or not B. ValueError
D. delete an attribute C. TypeError
ANSWER: D D. NameError
ANSWER: D
282. Say B is a subclass of A, to invoke the __init__
method in A from B, what is the line of code you
286. Evaluate the result of the following Python code,
should write?
if the time module has already been imported?
A. A.__init__(b)
5 + '4'
B. B.__init__(self)
A. NameError
C. A.__init__(self)
B. IndexError
D. B.__init__(a)
C. TypeError
ANSWER: C
D. ValueError
ANSWER: C
283. Is the following Python code valid?
try:
287. What exceptions are raised as a result of an error
# Do something in opening a particular file?
except: A. IOError
# Do something B. TypeError
finally: C. ImportError
# Do something D. ValueError
A. yes ANSWER: A
B. no, finally cannot be used with except
C. no, finally must come before except 288. What are Migrations in Django?
D. no, there is no such thing as finally A. Migrations are files where Django stores changes
to your models.
ANSWER: A
B. All of the above
C. They are created when you run makemigrations
284. Evaluate the result of the following Python code?
command.
lst = [11, 21, 31]
D. They are files saved in migrations directory.
lst[31]
ANSWER: B
A. NameError
B. ValueError
C. IndexError
D. TypeError
ANSWER: C
Page | 39
289. What does admin.autodiscover() do in Django? 293. Identify the code that will give us a text area form
field in Django?
A. It will look through INSTALLED_APPS when
admin is requested. A. Field_name = forms.TextAreaField()
B. If the installed apps have admin.py it will execute B. Field_name = forms.ButtonField(widgets =
them. forms.Textarea)
C. None of the above C. Field_name = forms.CharField(widgets =
forms.Textarea)
D. Both a and b
D. None of the above
ANSWER: D
ANSWER: C
292. Identify what are request.GET and request.POST 296. Identify the value of DEBUG when website is
objects? online/ or deployed using Django?
A. Python Dictionary-Like objects A. True
B. Python Lists B. False
C. Python Dictionaries C. None
D. None of the above D. Null
ANSWER: A ANSWER: B
Page | 40
297. Identify what does {{ forloop.counter }} prints in 301. Identify which of the following Password
Django? Validators are not provided by default in Django?
A. It prints the integer value of no. of times the loop A. NumericPasswordValidator
executed.
B. MaximumLengthValidator
B. It will count the number of times loop ran.
C. MinimumLengthValidator
C. It will not print if for loop variable is not defined.
D. CommonPasswordValidator
D. None of the above
ANSWER: B
ANSWER: A
Page | 41
306. Identify the result of this code in admin.py file in 310. Select the correct statement to run migrate
Django? command in Django?
admin.site.site_header = “Django Hello” A. py migrate
A. The title of Django's admin panel tab will change. B. py manage.py pymigrate
B. The admin will have no changes at all. C. py manage.py migrate
C. The admin will throw an error. D. run manage.py migrate
D. The heading of the admin panel will change. ANSWER: C
ANSWER: D
311. Except Django comment tag, what can be used to
write smaller comments?
307. Identify the Django command to view a database
schema of an existing (or legacy) database? A. {{# ... #}}
A. django-admin.py schemadump B. {# ... #}
B. manage.py inspect C. #..
C. manage.py inspectdb D. /* … *
D. manage.py legacydb ANSWER: B
ANSWER: C
312. Identify the Django tag which is used to include a
template inside the current template?
308. Identify the Django command to start a new app
named 'users' in an existing project?, A. insert
A. manage.py users B. allow
B. manage.py newapp users C. import
C. manage.py startapp users D. include
D. manage.py users start ANSWER: D
ANSWER: C
313. Which Django keyword is used to send variables
into the template?
309. What is the command used to create a new
Django Project? A. export
A. $ django-admin startproject project_name B. go
B. $ django createproject project_name C. with
C. $ django-admin createproject project_name D. send
D. $ django startproject project_name ANSWER: C
ANSWER: A
314. How can you define a one-to-many relationship
between two models in Django?
A. ManyToOneField()
B. models.ForeignKey()
C. ForeignKeyField()
D. OneToManyField()
ANSWER: B
Page | 42
315. Identify which is used as a global namespace for 319. Evaluate the result of the following Python
holding any data during the application context? expression if x=76.236?
A. Flask q object print("%.2f"%x)
B. Flask f object A. 76.236
C. Flask g object B. 76.23
D. Flask a object C. 76.0000
ANSWER: C D. 76.24
ANSWER: D
316. Identify the function used to display a message in
flask?
320. Evaluate the result of the following Python code?
A. flash()
print('*', "pqrst".center(6), '*', sep='')
B. display()
A. * tsrqp *
C. show()
B. *pqrst *
D. document()
C. error
ANSWER: A
D. none
ANSWER: B
317. Which of the following templates engines is the
default choice for Flask?
321. The process of pickling in Python includes
A. Handlebars
____________
B. Jinja
A. conversion of a list into a datatable
C. Mako
B. conversion of a datatable into a list
D. Django Templates
C. conversion of a byte stream into Python object
ANSWER: B hierarchy
D. conversion of a Python object hierarchy into byte
stream
318. Evaluate the result of the following Python code?
ANSWER: D
l=[11, 0, 21, 0, 'hello', '', []]
list(filter(bool, l))
322. Which of the following results in a SyntaxError?
A. [11, 0, 21, 'hello', ”, []]
A. '”Once upon a time…”, she said.'
B. Error
B. “He said, ‘Yes!'”
C. [11, 21, 'hello']
C. '5\'
D. [11, 0, 21, 0, 'hello', ”, []]
D. '’That’s okay”'
ANSWER: C
ANSWER: C
Page | 43
323. What does ~6 evaluate to? 328. Evaluate the result of the following Python
expression if X = -1122?
A. -7
print("-%06d"%X)
B. -4
A. −0001122
C. -3
B. 0001122
D. +3
C. −−01122
ANSWER: A
D. −001122
ANSWER: C
324. What does ~~~~~~6 evaluate to?
A. +6
329. Evaluate the result of the following Python
B. -11
expression if the value of x is 45?
C. +11
print(“%f”%x)
D. -5
A. 45.0
ANSWER: A
B. 45
C. 45.000000
325. Identify in the following expressions which
D. error
involves coercion when evaluated in Python?
ANSWER: C
A. 1.7 % 2
B. 7.9 * 6.3
330. Evaluate the result of the following Python code
C. 4.7 – 1.5
snippet?
D. 3.4 + 4.6
for i in ''.join(reversed(list('pqrs'))):
ANSWER: A
print (i)
A. p q r s
326. Evaluate the result of the following Python
B. s r q p
expression if x=789?
C. error
print("%-06d"%x)
D. none of the mentioned
A. 000789
ANSWER: B
B. 789000
C. 789
331. Evaluate the result of the following Python code?
D. error
print(0xA + 0xB + 0xc)
ANSWER: C
A. 33
B. Error
327. Evaluate the result of the following Python
expression if X=678? C. 0x22
print(“%06d”%X) D. 0xA0xB0xC
A. 678000 ANSWER: A
B. 000678
C. 000000678
D. 678000000
ANSWER: B
Page | 44
332. Evaluate the result of the following Python code? 336. What will be displayed by print(ord('d’)–
ord(‘c’))?
>>>max("what are you")
A. 0
A. error
B. 1
B. y
C. -1
C. t
D. 2
D. u
ANSWER: B
ANSWER: B
Page | 45
340. Evaluate the result of the following Python code? 344. Evaluate the result of the following Python code
snippet?
print('*', "pqrstu".center(7), '*')
print('The sum of {0:b} and {1:x} is {2:o}'.format(12,
A. pqrstu
110, 112))
B. * pqrstu *
A. The sum of 12 and 110 is 112
C. error
B. The sum of 110 and a is 114
D. none
C. The sum of 110 and a is c
ANSWER: B
D. Error
ANSWER: B
341. Evaluate the result of the following Python code?
print("ayyzayzazayy".count('ayy', -10, -1))
345. Evaluate the result of the following Python code
A. 2 snippet?
B. 0 print('{:,}'.format(1112223334))
C. 1 A. Error
D. error B. 111,222,333,4
ANSWER: B C. 1112223334
D. 1,112,223,334
342. Evaluate the result of the following Python code? ANSWER: D
print("abxyef".find("xy") == "xy" in "abxyef")
A. True 346. Evaluate the result of the following Python code
B. False snippet?
Page | 46
348. Evaluate the result of the following Python code 352. Evaluate the result of the following Python code
snippet? snippet?
print('5@ a'.isprintable()) print('Cd!2'.swapcase())
A. True A. CD!@
B. False B. cd12
C. None C. cD!2
D. Error D. error
ANSWER: A ANSWER: C
349. Evaluate the result of the following Python code? 353. Evaluate the result of the following Python code
snippet?
print('cba'.maketrans('abc', '123'))
print('abcd'.translate('a'.maketrans('abc', 'bcd')))
A. 123
A. bcde
B. {65: 49, 66: 50, 67: 51}
B. bcdd
C. 321
C. error
D. {97: 49, 98: 50, 99: 51}
D. abcd
ANSWER: D
ANSWER: B
Page | 47
355. Evaluate the result of the following Python code? 357. Evaluate the result of the following Python code?
names1 = ['John', 'Carey', 'Christian', 'David'] myList = [1, 3, 3, 3, 3, 1]
names2 = names1 max = myList[0]
names3 = names1[:] indexOfMax = 0
names2[0] = 'Alice' for i in range(1, len(myList)):
names3[1] = 'Bob' if myList[i] > max:
sum = 0 max = myList[i]
for ls in (names1, names2, names3): indexOfMax = i
if ls[0] == 'Alice': >>>print(indexOfMax)
sum += 1 A. 1
if ls[1] == 'Bob': B. 2
sum += 10 C. 3
print sum D. 4
A. 12 ANSWER: A
B. 11
C. 21 358. Evaluate the result of the following Python code?
D. 22 myList = [10, 20, 30, 40, 50, 60]
ANSWER: A for i in range(1, 6):
myList[i - 1] = myList[i]
356. Say list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 for i in range(0, 6):
after list1.extend([28, 7])?
print(myList[i], end = " ")
A. [3, 4, 5, 20, 5, 25, 1, 3, 28, 7]
A. 20 30 40 50 60 10
B. [1, 3, 3, 4, 5, 5, 20, 25, 28, 7]
B. 60 10 20 30 40 50
C. [25, 20, 5, 5, 4, 3, 3, 1, 28, 7]
C. 20 30 40 50 60 60
D. [1, 3, 4, 5, 20, 5, 25, 3, 28, 7]
D. 10 10 20 30 40 50
ANSWER: A
ANSWER: C
Page | 48
359. Evaluate the result of the following Python code? 362. Evaluate the result of the following Python code?
def example(L): values = [[3, 4, 5, 1], [25, 6, 1, 2]]
''' (list) -> list v = values[0][0]
''' for row in range(0, len(values)):
i=0 for column in range(0, len(values[row])):
result = [] if v < values[row][column]:
while i < len(L): v = values[row][column]
result.append(L[i]) print(v)
i=i+3 A. 3
return result B. 5
A. error C. 6
B. Return an empty list D. 25
C. Return a list containing every third item from L ANSWER: D
starting at index 0
D. Return a list containing the items from L starting
363. Evaluate the result of the following Python code?
from index 0, omitting every third item
values = [[33, 43, 53, 13 ], [333, 63, 13, 23]]
ANSWER: C
for row in values:
row.sort()
360. Evaluate the result of the following Python code?
for element in row:
veggies = ['carrot', 'broccoli', 'potato', 'asparagus']
print(element, end = " ")
veggies.insert(veggies.index('broccoli'), 'celery')
print()
print(veggies)
A. The program prints two rows 33 43 53 13 followed
A. [‘celery’, ‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’]
by 333 63 13 23
B. [‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]
B. The program prints on row 33 43 53 13 333 63 13
C. [‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’] 23
D. [‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’] C. The program prints two rows 33 43 53 13 followed
by 333 63 13 23
ANSWER: D
D. The program prints two rows 13 33 43 53 followed
by 13 23 63 333
361. Evaluate the result of the following Python code?
ANSWER: D
>>>m = [[y, y + 1, y + 2] for y in range(0, 3)]
A. [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
B. [0, 1, 2, 1, 2, 3, 2, 3, 4]
C. [1, 2, 3, 4, 5, 6, 7, 8, 9]
D. [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
ANSWER: D
Page | 49
364. Evaluate the result of the following Python code? 367. Evaluate the result of the following Python code?
import copy a=[11,21,31,41]
a=[101,231,561,[781]] b=[sum(a[0:x+1]) for x in range(0,len(a))]
b=copy.deepcopy(a) print(b)
a[3][0]=951 A. 10
a[1]=341 B. [11,31,51,71]
print(b) C. 41
A. [101,341,561,[951]] D. [11,32,63,104]
B. [101,231,561,[781]] ANSWER: D
C. [101,231,561,[951]]
D. [101,341,561,[781]] 368. Evaluate the result of the following Python code?
ANSWER: B a=[[]]*4
a[1].append(9)
365. Evaluate the result of the following Python code? print(a)
a=[10,20,30,40] A. Syntax error
b=[sum(a[0:x+1]) for x in range(0,len(a))] B. [[9], [9], [9], [9]]
print(b) C. [[9], [], []]
A. 100 D. [[],9, [], []]
B. [10,30,50,70] ANSWER: B
C. 40
D. [10,30,60,100] 369. Evaluate the result of the following Python code?
ANSWER: D def unpack(a,b,c,d):
print(a+d)
366. Evaluate the result of the following Python code? x = [12,22,32,42]
y='hello' unpack(*x)
z=list((x.upper(),len(x)) for x in y) A. Error
print(z) B. [1,4]
A. error C. [50]
B. [(‘HELLO’, 5)] D. 54
C. [(‘H’, 5), (‘E’, 5), (‘L’, 5), (‘L’, 5), (‘O’, 5)] ANSWER: D
D. [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1)]
ANSWER: D
Page | 50
370. Evaluate the result of the following Python code? 373. Evaluate the result of the following Python code
snippet?
a = [12, 52, 72, 92, 92, 12]
for x in range(3):
b=a[0]
if x%2==0:
x= 0
print(x)
for x in range(1, len(a)):
else:
if a[x] > b:
print(x+1)
b = a[x]
A. [0, 2, 2]
b= x
B. [1, 1, 3]
print(b)
C. error
A. 5
D. none of the mentioned
B. 3
ANSWER: C
C. 4
D. 0
374. Evaluate the result of the following Python code?
ANSWER: A
l1=[10,20,30]
l2=[40,50,60]
371. Evaluate the result of the following Python code?
print([x*y for x in l1 for y in l2])
a=["Ant","Bat","Cat"]
A. [40, 80, 120, 50, 100, 150, 60, 120, 180]
a.sort(key=len)
B. [400, 1000, 1800]
print(a)
C. [400, 500, 600, 800, 1000, 1200, 1200, 1500,
A. [‘Ant’, ‘Bat’, ‘Cat’]
1800]
B. [‘Bat’, ‘Ant’, ‘Cat’]
D. [180, 120, 60, 150, 100, 50, 120, 80, 40]
C. [‘Cat’, ‘Ant’, ‘Bat’]
ANSWER: C
D. Invalid syntax for sort()
ANSWER: A
375. Evaluate the result of the following Python code?
A = [[11, 21, 31],
372. Evaluate the result of the following Python code
[41, 51, 61],
snippet?
[71, 81, 91]]
x = [i**+2 for i in range(2)]; print(x);
print([[col + 10 for col in row] for row in A])
A. [0, 1]
A. [[21, 31, 41], [51, 61, 71], [81, 91, 101]]
B. [1, 2]
B. Error
C. error, **+ is not a valid operator
C. [11, 12, 13], [14, 15, 16], [17, 18, 19]
D. error, ‘;’ is not allowed
D. [11, 12, 13, 14, 15, 16, 17, 18, 19]
ANSWER: A
ANSWER: A
Page | 51
376. Evaluate the result of the following Python code?
a = [50,50,60,70,70,70] 378. Evaluate the result of the following Python code?
b = set(a) class trial:
def test(lst): def __init__(self):
if lst in b: pass
return 1 def test(self):
else: print(__name__)
return 0 obj1 = trial()
for i in filter(test, a): obj1.test()
print(i,end=" ") A. Exception is thrown
A. 50 50 60 B. __main__
B. 50 60 70 C. Demo
C. 50 50 60 70 70 70 D. test
D. 50 60 70 70 70 ANSWER: B
ANSWER: C
379. Evaluate the result of the following Python code?
377. Evaluate the result of the following Python code. #generator
Suppose, "data.txt" is a file.
def f(y):
f = None
yield y+1
for i in range (3):
p=f(5)
with open("data.txt", "w") as f:
print(next(p))
if i > 2:
A. 4
break
B. 6
print(f.closed)
C. 10
A. Code is correct
D. Error
B. Code is wrong
ANSWER: B
C. None
D. Can't say
380. Evaluate the result of the following Python code?
ANSWER: A
def f(y):
for i in range(4):
yield i
p=f(6)
print(list(p))
A. [0, 1, 2, 3]
B. [1, 2, 3, 4, 5, 6]
C. [1, 2, 3, 4]
D. [0, 1]
ANSWER: A
Page | 52
381. Evaluate the result of the following Python code? 384. Evaluate the result of the following Python code
snippet?
def show(m):
st1 = ['s','f','a','e']
if m<1 or m>12:
k = [print(i) for i in st1 if i not in "aeiou"]
raise ValueError("Invalid")
print(k)
print(m)
A. prints all the vowels in st1
show(5)
B. error
A. ValueError
C. prints all characters of st1 that aren’t vowels
B. Invalid
D. no output
C. 5
ANSWER: C
D. ValueError(“Invalid”)
ANSWER: C
385. Evaluate the result of the following Python code
snippet?
382. Evaluate the result of the following Python code?
st1 = "evening"
def p(list):
p = [(i.upper(), len(i)) for i in st1]
v = list[0]
print(p)
for e in list:
A. error
if v < e: v = e
B. [('E', 1), ('V', 1), ('E', 1), ('N', 1), ('I', 1), ('N', 1),
return v ('G', 1)]
values = [[13, 14, 15, 11], [33, 16, 11, 12]] C. [(‘EVENING’, 7)]
for row in values: D. none of the mentioned
print(p(row), end = " ") ANSWER: B
A. 13 33
B. 11 11 386. Identify the purpose of __str__() method in
C. 15 16 Django?
Page | 53
387. In the following code in Django framework, 390. Identify the setting that contains the parameter of
evaluate the result of variable m? main-urls file in Django?
from post.models import * A. STATIC_URL
m = Post.objects.filter(post_heading=”post1″) B. MAIN_URLCONF
m C. ROOT_URLCONF
A. It will print all the objects which match the D. MEDIA_URL
heading “post1”.
ANSWER: C
B. It will print all objects.
C. It will print the first object which matched with
391. Identify the use of os.path.dirname(__file__) in
heading “post1” in argument.
this method?
D. None of the above
A. It is used to pass the value of current file in which
ANSWER: A this line is written.
B. It is passing some value defined before.
388. In Post.models.filter() you can pass multiple C. It is the default value and points to Django
parameters in filter() to narrow your result/s in settings.py.
Django.
D. None of the above
A. False
ANSWER: A
B. True
C. Can’t say
392. Identify the type of configuration Django requires
D. None of the above for logging?
ANSWER: B A. Django requires a dictConfig in settings.py.
B. Django requires a configuration of handlers and
loggers.
389. In Django, what effect does this parameter
causes? C. Django requires no configuration. Use logging by
an import.
from post.models import *
D. Logging can be directly used in each module
m = Post.objects.filter(post_heading__contains=”post”)
separately.
m
ANSWER: A
A. It will throw an error as no
post_heading__contains field does not exist.
393. Python support which type of Programming?
B. It will search for field post_heading__contains and
match value with them. A. object-oriented programming
C. It will return the first object it matched the value B. all of the mentioned
with.
C. functional programming
D. It will select all the posts having post in their
D. structured programming
post_heading name.
ANSWER: B
ANSWER: D
Page | 54
394. Identify which of the following is the correct 398. Identify which of the following is true for variable
extension of the Python file? names in Python?
A. .python A. underscore and ampersand are the only two special
characters allowed
B. .plt
B. all private members must have leading and trailing
C. .pk
underscores
D. .py
C. unlimited length
ANSWER: D
D. none of the mentioned
ANSWER: C
395. What will be the value of the following Python
expression?
399. Identify which of the following is not a core data
4+3%5
type in Python programming?
A. 13
A. Class
B. 2
B. Lists
C. 4
C. Tuples
D. 7
D. Dictionary
ANSWER: D
ANSWER: A
Page | 55
402. In Django how would you retrieve all the 'User' 407. What core data type we use in order to store
records from a given database? values in terms of key and value.
A. User.objects.all() A. dictionary
B. Users.objects.all() B. tuple
C. User.all_records() C. class
D. User.object.all() D. list
ANSWER: A ANSWER: A
403. Identify which of the following is a Python tuple? 408. Identify what function do you use to read a
string?
A. [1, 2, 3]
A. enter(“Enter a string”)
B. {}
B. eval(input(“Enter a string”))
C. {1, 2, 3}
C. input(“Enter a string”)
D. (1, 2, 3)
D. eval(enter(“Enter a string”))
ANSWER: A
ANSWER: C
Page | 56
411. Say listExample is [‘h’,’e’,’l’,’l’,’o’], what is 415. Identify which of the following statements create
len(listExample)? a dictionary?
A. 4 A. All of the mentioned
B. 5 B. d = {“john”:40, “peter”:45}
C. None C. d = {40:”john”, 45:”peter”}
D. Error D. d = {}
ANSWER: B ANSWER: A
412. Evaluate the result of the following Python code? 416. Identify which of these about a dictionary is
false?
d = {"john":40, "peter":45}
A. The values of a dictionary can be accessed using
d["john"]
keys
A. “peter”
B. Dictionaries are mutable
B. 45
C. Dictionaries aren’t ordered
C. “john”
D. The keys of a dictionary can be accessed using
D. 40 values
ANSWER: D ANSWER: D
413. Evaluate the result of the following Python code? 417. Identify which keyword is used for function?
>>>t = (1, 2) A. def
>>>2 * t B. Define
A. [1, 1, 2, 2] C. Fun
B. [1, 2, 1, 2] D. Function
C. (1, 1, 2, 2) ANSWER: A
D. (1, 2, 1, 2)
ANSWER: D 418. Identify which of the following best describes
inheritance?
414. Identify which of the following statements is used A. Focuses on variables and passing of variables to
to create an empty set? functions
Page | 57
419. When is the finally block executed? 424. Evaluate the result of the following Python code?
A. when there is no exception >>>list1 = [1, 3]
B. always >>>list2 = list1
C. only if some condition that has been specified is >>>list1[0] = 4
satisfied
>>>print(list2)
D. when there is an exception
A. [4, 3]
ANSWER: B
B. [1, 3, 4]
C. [1, 4]
420. What does {{ name }} this mean in Django
D. [1, 3]
Templates?
ANSWER: A
A. It will be displayed as name in HTML.
B. None of the above
425. Identify which one of the following is the use of
C. {{ name }} will be the output.
function in python?
D. The name will be replaced with values of Python
A. Functions are reusable pieces of programs
variable.
B. you can’t also create your own functions
ANSWER: D
C. Functions don’t provide better modularity for your
application
421. Django is a type of?
D. All of the mentioned
A. Software
ANSWER: A
B. None
C. Programming Language
426. Identify what error occurs when you execute the
D. Web Framework following Python code snippet?
ANSWER: D apple = mango
A. SyntaxError
422. Flask is a? B. TypeError
A. peraframework C. ValueError
B. miniframework D. NameError
C. microframework ANSWER: D
D. nanoframework
ANSWER: C 427. Evaluate the result of the following Python code
snippet?
not(11<21) and not(11>31)
423. Identify which of the following is the use of id()
function in python? A. True
A. Every object doesn’t have a unique id B. False
B. None of the mentioned C. Error
C. All of the mentioned D. No output
D. Id returns the identity of the object ANSWER: B
ANSWER: D
Page | 58
428. Evaluate the result of the following Python code? 432. What is “Hello”.replace(“l”, “e”)?
x = ['abc', 'cde'] A. None
for i in x: B. Heelo
i.upper() C. Heleo
print(x) D. Heeeo
A. [‘abc’, ‘cde’] ANSWER: D
B. [‘ABC’, ‘CDE’]
C. [None, None] 433. Evaluate the result of the following Python code
snippet?
D. none of the mentioned
print('abcdef12'.replace('cd', '12'))
ANSWER: A
A. none of the mentioned
B. abcdef12
429. Evaluate the result of the following Python
statement? C. ab12efcd
>>>"efgh"[2:] D. ab12ef12
A. e ANSWER: D
B. ef
C. gh 434. Say list1 is [2, 33, 222, 14, 71], What is list1[-1]?
D. hg A. Error
ANSWER: C B. None
C. 71
430. Evaluate the result of the following Python code? D. 2
>>> str1 = 'hello' ANSWER: C
>>> str2 = ','
>>> str3 = 'world' 435. Evaluate the result of the following Python code?
>>> str1[-1:] >>>list1 = [12, 3, 24]
A. olleh >>>list2 = [12, 3, 3]
B. hello >>>list1 < list2
C. o A. True
D. h B. False
ANSWER: C C. Error
D. None
431. Evaluate the result of the following Python code? ANSWER: B
>>>print (r"\nhi")
A. a new line and hi
B. \nhi
C. the letter r and then hi
D. error
ANSWER: B
Page | 59
436. Evaluate the result of the following Python code?
>>>list1 = [1, 3] 439. Say t = (1, 2, 4, 3), which of the following is
wrong?
>>>list2 = list1
A. print(t[3])
>>>list1[0] = 5
B. t[5] = 94
>>>print(list2)
C. print(max(t))
A. [1, 3]
D. print(len(t))
B. [5, 3]
ANSWER: B
C. [1, 5]
D. [1, 3, 5]
440. Evaluate the result of the following Python code?
ANSWER: B
>>>t=(1,21,41,3)
>>>t[1:-1]
437. Evaluate the result of the following Python code?
A. (1, 21)
def f(values):
B. (1, 21, 41)
values[0] = 61
C. (21, 41)
v = [1, 2, 3]
D. (21, 41, 3)
f(v)
ANSWER: C
print(v)
A. [1, 61]
441. Is the following Python code valid?
B. [1, 2, 3, 61]
>>> a=(10,20,30,40)
C. [61, 2, 3]
>>> del a
D. [1, 2, 3]
A. No because tuple is immutable
ANSWER: C
B. Yes, first element in the tuple is deleted
C. Yes, the entire tuple is deleted
438. Evaluate the result of the following Python code?
D. No, invalid syntax for del method
numbers = [9, 10, 11, 12]
ANSWER: C
numbers.append([5,6,7,8])
print(len(numbers))
442. If a={5,6,7,8}, which of the following statements
A. 4
is false?
B. 5
A. print(len(a))
C. 8
B. print(min(a))
D. 12
C. a.remove(5)
ANSWER: B
D. a[22]=39
ANSWER: D
Page | 60
443. If a={5,6,7}, what happens when a.add(5) is 447. Say d = {“sam”:40, “peter”:45}, to delete the
executed? entry for “sam” what command do we use?
A. a={5,5,6,7} A. d.delete(“sam”:40)
B. Error as 5 already exists in the set B. d.delete(“sam”)
C. Error as there is no add function for set data type C. del d[“sam”]
D. a={5,6,7} D. del d(“sam”:40)
ANSWER: D ANSWER: C
444. Evaluate the result of the following Python code? 448. Say d = {“sam”:40, “peter”:45}. To obtain the
number of entries in dictionary which command do
>>> s={52,62}
we use?
>>> s*3
A. d.size()
A. Error as unsupported operand type for set data type
B. len(d)
B. {52,62,52,62,52,62}
C. size(d)
C. {52,62}
D. d.len()
D. Error as multiplication creates duplicate elements
ANSWER: B
which isn’t allowed
ANSWER: A
449. What type of inheritance is illustrated in the
following Python code?
445. Evaluate the result of the following Python code?
class D():
>>> a={4,6,7}
pass
>>> sum(a,5)
class E():
A. 5
pass
B. 22
class F(D,E):
C. 18
pass
D. Invalid syntax for sum method, too many
A. Multi-level inheritance
arguments
B. Multiple inheritance
ANSWER: B
C. Hierarchical inheritance
D. Single-level inheritance
446. Evaluate the result of the following Python code?
ANSWER: B
>>> a={51,61,71,81}
>>> b={71,81,91,101}
450. Which of the following is not a standard
>>> len(a+b)
exception in Python?
A. 8
A. NameError
B. Error, unsupported operand ‘+’ for sets
B. IOError
C. 6
C. ArrayAssignmentError
D. Nothing is displayed
D. ValueError
ANSWER: B
ANSWER: C
Page | 61
451. What does {% include %} does? 455. Evaluate the result of the following Python code?
A. None of the above d = {0: 'd', 1: 'e', 2: 'f'}
B. It will include content from another template for x in d.keys():
having the same templates defined.
print(d[x])
C. It is the same as {% extend %}.
A. 0 1 2
D. It will include another template.
B. d e f
ANSWER: D
C. 0 d 1e 2f
D. none of the mentioned
452. Which method is used instead of path() in urls.py
ANSWER: B
to pass in regular expressions as routes in Django?
A. static()
456. Evaluate the result of the following Python code?
B. url()
d = {0, 4, 5}
C. include()
for x in d.values():
D. re_path()
print(x)
ANSWER: B
A. 0 4 5
B. None None None
453. What is the purpose of settings.py in Django?
C. error
A. To configure settings for the Django project
D. none of the mentioned
B. To set the date and time on the server
ANSWER: C
C. To configure settings for an app
D. To sync the database schema
457. Evaluate the result of the following Python code?
ANSWER: A
d = {3, 4, 5}
for x in d:
454. Identify which of the following will run without
errors? print(d.add(x))
A. round(35.7) A. 3 4 5
B. round(1234.898,2,5) B. 3 4 5 3 4 5 3 4 5 …
C. round() C. None None None
D. round(5678.123,2,1) D. None of the mentioned
ANSWER: A ANSWER: C
Page | 62
458. Evaluate the result of the following Python code? 462. Evaluate the result of the following Python code?
x = (i for i in range(4)) names1 = ['Amir', 'Bala', 'Marlie']
for i in x: names2 = [name.lower() for name in names1]
print(i) print(names2[2][0])
A. 0 1 2 3 A. None
B. error B. a
C. 0 1 2 0 1 2 C. b
D. none of the mentioned D. m
ANSWER: A ANSWER: D
459. Evaluate the result of the following Python code 463. How many elements are in m?
snippet?
m = [[a, b] for a in range(0, 4) for b in range(0, 4)]
a = [0, 1, 2, 3]
A. 8
for a[-1] in a:
B. 12
print(a[-1])
C. 16
A. 3 2 1 0
D. 32
B. error
ANSWER: C
C. 3 3 3 3
D. 0 1 2 2
464. Identify the true statement.
ANSWER: D
A. When you open a file for reading, if the file does
not exist, an error occurs
460. Evaluate the result of the following Python code? B. When you open a file for writing, if the file does
not exist, a new file is created
>>>names = ['Anthony', 'Bill', 'Charlie', 'Saman']
C. All of the mentioned
>>>print(names[-1][-1])
D. When you open a file for writing, if the file exists,
A. A
the existing file is overwritten with the new file
B. Saman
ANSWER: C
C. Error
D. n
465. To read three characters from a file object infile,
ANSWER: D we use ____________
A. infile.read(3)
461. Say list1 = [0.5 * z for z in range(0, 4)], list1 is: B. infile.read()
A. [0, 1, 2, 3] C. infile.readline()
B. [0, 1, 2, 3, 4] D. infile.readlines()
C. [0.0, 0.5, 1.0, 1.5, 2.0] ANSWER: A
D. [0.0, 0.5, 1.0, 1.5]
ANSWER: D
Page | 63
466. Identify the use of tell() method in python? 470. Evaluate the result of the following Python code?
A. file is opened or not matrix = [[1, 21, 3, 4],
B. end position within the file [4, 51, 6, 7],
C. current position within the file [8, 91, 10, 11],
D. none of the mentioned [12, 131, 14, 15]]
ANSWER: A for i in range(0, 4):
print(matrix[i][1], end = " ")
467. Identify the use of seek() method in files? A. 1 2 3 4
A. sets the file's current position within the file B. 4 5 6 7
B. sets the file's previous position at the offset C. 1 3 8 12
C. sets the file's current position at the offset D. 21 51 91 131
D. none of the mentioned ANSWER: D
ANSWER: C
471. Evaluate the result of the following Python
expression?
468. In Django, What is Post.objects.all() is used for?
float(3+int(2.39)%2)
A. Post object will bring objects from database with
SQL Query: Select *. A. 5.0
B. It is used to create a new Post object m. B. 5
C. It is used to bring all the objects stored in Post C. 3.0
table.
D. 4
D. None of the above
ANSWER: C
ANSWER: C
Page | 64
473. Suppose list1 is [5, 3, 4], What is list1 * 2? 478. Identify which of the following the “in” operator
can be used to check if an item is in it?
A. [2, 6, 4]
A. Lists
B. [5, 3, 2, 1, 3]
B. Dictionary
C. [5, 3, 4, 5, 3, 4]
C. All of the mentioned
D. [5, 3, 2, 3, 2, 1]
D. Set
ANSWER: C
ANSWER: C
Page | 65
481. Which of the following Python statements will 485. Evaluate the result of the following Python code?
result in the output: 11?
>>> a={2,3,4,5}
A = [[1, 2, 3],
>>> b={4,5,3,2}
[4, 5, 11],
>>> a==b
[7, 8, 9]]
A. True
A. A[2][3]
B. False
B. A[2][1]
C. Error
C. A[1][2]
D. No output
D. A[3][2]
ANSWER: A
ANSWER: C
Page | 66
488. Identify which of the following is not a valid
namespace?
A. Global namespace
B. Local namespace
C. Built-in namespace
D. Public namespace
ANSWER: D
Page | 67