MCQ ON PYTHON
Python MCQ’s
1. Is Python case sensitive when dealing with identifiers?
a) yes
2
3
4
d) _
5 Why are local variable names beginning with an underscore discouraged?
a) they are used to indicate a private variables of a class
b) they confuse the interpreter
c) they are used to indicate global variables
d) they slow down execution
6 Which of the following is not a keyword?
a) eval
b) assert
7
8
9
10 Which of these in not a core data type?
a) Lists
b) Dictionary
c) Tuples
d) Class
11 Given a function that does not return any value, What value is thrown by default when executed in shell.
a) int
b) bool
c) void
d) None
15 What will be the output of the following Python code snippet?
5.>>>example("hello")
a) indentation Error
b) cannot perform mathematical operation on strings
c) hello2
19 . What is the average value of the following Python code snippet?
a) 85.0
b) 85.1
c) 95.0
d) 95.1
20. What is the return value of trunc()?
a) int
a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,iv,vi,v
24. What is the answer to this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5
25. Mathematical operations can be performed on a string.
b) False
30. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
31. What is the output of print 0.1 + 0.2 == 0.3?
a) True
b) False
c) Machine dependent
c) +11
d) -5
36. Which of the following is incorrect? a) x = 0b101
b) x = 0x4f5
c) x = 19023
d) x = 03964
37. What is the result of cmp(3, 1)?
a) 1
b) 0
c) True
a) [‘ab’, ‘cd’]
b) [‘AB’, ‘CD’]
c) [None, None]
d) none of the mentioned
43. What will be the output of the following Python code?
a) [‘AB’, ‘CD’]
b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]
c) [‘ab’, ‘cd’]
a) 5 6 7 8 9 10
b) 5 6 7 8
c) 5 6
d) error
47. What will be the output of the following Python code?
a) 2 4 6 8 10 …
b) 2 4
c) 2 3
d) error
50. What will be the output of the following Python code?
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned
54. What will be the output of the following Python code?
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned
58. What will be the output of the following Python code?
a) 0
b) no output
c) error
d) none of the mentioned
62. What will be the output of the following Python code?
a) 0 1 2 0
b) 0 1 2
c) error
d) none of the mentioned
63. What will be the output of the following Python code?
a) 0 1 2 3 0
b) 0 1 2 0
c) 0 1 2
d) error
64. What will be the output of the following Python code?
a) a b c d e f
b) abcdef
c) i i i i i i …
d) error
65. What will be the output of the following Python code?
a) no output
b) i i i i i i …
a) i i i i i i
b) a a a a a a
c) a a a a a
d) none of the mentioned
69. What will be the output of the following Python code?
a) a a a a a a
b) a
c) no output
d) error
72. What will be the output of the following Python code?
a) 0.0 1.0
b) 0 1
c) error
a) 0.0 0.1 0.2 0.3 …
b) 0 1 2 3 …
c) 0.0 1.0 2.0 3.0 …
d) none of the mentioned
76. What will be the output of the following Python code snippet?
a) 1 2 3 4
b) 4 3 2 1
b) (nothing is printed)
c) error
d) none of the mentioned
80. What will be the output of the following Python code snippet?
x = 2
a) 0 1 2 3 4 …
b) 0 1
c) 3 4
a) a b c d
b) A B C D
c) a B C D
d) error
84. What will be the output of the following Python code?
a) a b c d
b) 0 1 2 3
c) error
d) none of the mentioned
88. What will be the output of the following Python code snippet?
91. What will be the output of the following Python code snippet?
a) a
b) abcd abcd abcd abcd
c) a a a a
d) none of the mentioned
92. What will be the output of the following Python code?
a) 0 1 2
b) error
c) 0 1 2 0 1 2
d) none of the mentioned
95. What will be the output of the following Python code?
a) 0 1 2 3
b) 0 1 2 2
c) 3 3 3 3
d) error
99. What will be the output of the following Python code snippet?
a) 0 1 2 3
a) list1 = list()
b) list1 = []
c) list1 = list([1, 2, 3])
d) all of the mentioned
103. What is the output when we execute list(“hello”)?
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]
104. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
109. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
a) print(list1[0])
b) print(list1[:2])
c) print(list1[:-2])
d) all of the mentioned
110. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
a) Error
b) None
c) 25
d) 2
111. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]? a) [2, 33, 222, 14]
b) Error
c) 25
d) [25, 14, 222, 33, 2]
112. What will be the output of the following Python code?
a) A
b) Daman
c) Error
d) n
113. What will be the output of the following Python code?
a) 11
b) 12
c) 21
d) 22
114. Suppose list1 is [1, 3, 2], What is list1 * 2?
a) [2, 6, 4]
b) [1, 3, 2, 1, 3]
c) [1, 3, 2, 1, 3, 2]
d) [1, 3, 2, 3, 2, 1]
115. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
a) [0, 1, 2, 3]
b) [0, 1, 2, 3, 4]
c) [0.0, 0.5, 1.0, 1.5]
d) [0.0, 0.5, 1.0, 1.5, 2.0]
116. What will be the output of the following Python code?
a) True
b) False
c) Error
d) None
117. To add a new element to a list we use which command?
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)
118. To insert 5 to the third position in list1, we use which command?
a) list1.insert(3, 5)
b) list1.insert(2, 5)
c) list1.add(3, 5)
d) list1.append(3, 5)
119. To remove string “hello” from list1, we use which command?
a) list1.remove(“hello”)
b) list1.remove(hello)
c) list1.removeAll(“hello”)
d) list1.removeOne(“hello”)
120. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
a) 0
b) 1
c) 4
d) 2
121. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
125. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?
a) [3, 4, 5, 20, 5, 25, 1]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]
126. What will be the output of the following Python code?
1. >>>"Welcome to Python".split()
a) [“Welcome”, “to”, “Python”]
129. What will be the output of the following Python code?
a) 2 3 4 5 6 1
b) 6 1 2 3 4 5
c) 2 3 4 5 6 6
d) 1 1 2 3 4 5
130. What will be the output of the following Python code?
a) [1] [2] [3]
b) [1] [1, 2] [1, 2, 3]
c) [1, 2, 3]
d) 1 2 3
133. What will be the output of the following Python code?
a) None
b) 1
c) 2
d) Error
134. What will be the output of the following Python code?
a) None
b) a
c) b
d) c
135. What will be the output of the following Python code?
a) 4
b) 5
c) 8
d) 12
136. To which of the following the “in” operator can be used to check if an item is in it?
a) Lists
b) Dictionary
c) Set
d) All of the mentioned
137. What will be the output of the following Python code?
a) 2
b) 4
c) 5
d) 8
138. What will be the output of the following Python code?
a) [‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’] Correct 1.00
b) [‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]
c) [‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]
d) [‘celery’, ‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’]
141. What will be the output of the following Python code?
1.>>>m = [[x, x + 1, x + 2] for x 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]
142. How many elements are in m?
1.m = [[x, y] for x in range(0, 4) for y in range(0, 4)]
a) 8
b) 12
c) 16
d) 32
143. What will be the output of the following Python code?
a) 3
b) 5
c) 6
d) 33
144. What will be the output of the following Python code?
a) 1
b) 3
c) 5
d) 6
145. What will be the output of the following Python code?
a) The program prints two rows 3 4 5 1 followed by 33 6 1 2
b) The program prints on row 3 4 5 1 33 6 1 2
c) The program prints two rows 3 4 5 1 followed by 33 6 1 2
d) The program prints two rows 1 3 4 5 followed by 1 2 6 33
146. What will be the output of the following Python code?
a) 1 2 3 4
b) 4 5 6 7
c) 1 3 8 12
d) 2 5 9 13
147. What will be the output of the following Python code?
a) 3 33
b) 1 1
c) 5 6
a) [[1, 2], [3, 1.5], [0.5, 0.5]]
b) [[3, 1.5], [1, 2], [0.5, 0.5]]
c) [[0.5, 0.5], [1, 2], [3, 1.5]]
d) [[0.5, 0.5], [3, 1.5], [1, 2]]
151. What will be the output of the following Python code?
a) [10,34,56,[95]]
b) [10,23,56,[78]]
c) [10,23,56,[95]]
d) [10,34,56,[78]]
152. What will be the output of the following Python code?
a) [10,34,56,[95]]
b) [10,23,56,[78]]
c) [10,23,56,[95]]
d) [10,34,56,[78]]
153. What will be the output of the following Python code?
a) 10
b) [1,3,5,7]
c) 4
d) [1,3,6,10]
154. What will be the output of the following Python code?
a) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1)]
b) [(‘HELLO’, 5)]
c) [(‘H’, 5), (‘E’, 5), (‘L’, 5), (‘L’, 5), (‘O’, 5)]
a) [2,4]
b) [ ]
c) [3,5]
d) Invalid arguments for filter function
158. What will be the output of the following Python code?
a) [[3],[7]]
b) [1,2,3,4]
c) Error
d) [10]
162. What will be the output of the following Python code?
a) Error
b) [1,4]
c) [5]
d) 5
163. What will be the output of the following Python code?
a) [‘Bangalore’, ‘Pune’, ‘Hyderabad’]
b) [‘Bangalore’, ‘Pune’, ‘Delhi’]
c) [‘Bangalore’, ‘Mumbai’, ‘Delhi’]
d) [‘Bangalore’, ‘Mumbai’, ‘Hyderabad’]
164. What will be the output of the following Python code?
a) [1] [2]
b) [49] [50]
c) Syntax error
d) [[1]] [[2]]
165. What will be the output of the following Python code?
a) 561
b) 5
c) 12
d) Syntax error
166. What will be the output of the following Python code?
a) [‘Apple’, ‘Ball’, ‘Cobra’]
b) [‘Ball’, ‘Apple’, ‘Cobra’]
c) [‘Cobra’, ‘Apple’, ‘Ball’]
d) Invalid syntax for sort()
169. What will be the output of the following Python code?
a) [(‘HELLO’, 5), (‘WORLD’, 5)]
b) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
c) [(‘HELLO WORLD’, 11)]
d) none of the mentioned
173. What will be the output of the following Python code snippet?
x = [i**+1 for i in range(3)]; print(x);
a) [0, 1, 2]
b) [1, 2, 5]
c) error, **+ is not a valid operator
c) [[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
d) [‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]
177. What will be the output of the following Python code snippet?
print([if i%2==0: i; else: i+1; for i in range(4)])
a) [0, 2, 2, 4]
b) [1, 1, 3, 3]
c) error
d) none of the mentioned
178. Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3]))?
a) [x**-1 for x in [(1, 2, 3)]]
b) [1/x for x in [(1, 2, 3)]]
c) [1/x for x in (1, 2, 3)]
d) error
179. What will be the output of the following Python code?
a) [1, 1, 1, 1, 1]
b) [1, 0, 1, 0, 1]
c) [1, 0, 0, 0, 0]
d) [0, 1, 0, 1, 0]
180. What will be the output of the following Python code?
a) [4, 8, 12, 5, 10, 15, 6, 12, 18]
b) [4, 10, 18]
c) [4, 5, 6, 8, 10, 12, 12, 15, 18]
d) [18, 12, 6, 15, 10, 5, 12, 8, 4]
181. Write the list comprehension to pick out only negative integers from a given list ‘l’.
a) [x<0 in l]
b) [x for x<0 in l]
c) [x in l for x<0]
d) [x for x in l if x<0]
182. What will be the output of the following Python code?
s=["pune", "mumbai", "delhi"]
[(w.upper(), len(w)) for w in s]
a) Error
b) [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]
c) [PUNE, 4, MUMBAI, 6, DELHI, 5]
d) [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]
186. Read the information given below carefully and write a list comprehension such that the
output is: [‘e’, ‘o’]
a) [x for w in v if x in v]
b) [x for x in w if x in v]
c) [x for x in v if w in v]
d) [x for v in w for x in w]
187. What will be the output of the following Python code?
a) [i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
b) [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
c) [i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
d) [i for i in range(1, 100) if int(i*0.5)=(i*0.5)]
191. What is the list comprehension equivalent for: list(map(lambda x:x**-1, [1, 2, 3]))?
a) [1|x for x in [1, 2, 3]]
b) [-1**x for x in [1, 2, 3]]
c) [x**-1 for x in [1, 2, 3]]
d) [x^-1 for x in range(4)]
192. Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].
a) [‘good’, ‘oh’, ‘excellent’, ‘450’ ]
b) [‘good’]
c) [‘good’, ‘#450’]
d) [‘oh!’, ‘excellent!’, ‘#450’]
196. What will be the output of the following Python code?
a) [1, 5, 9]
b) [3, 5, 7]
c) [4, 5, 6]
d) [2, 5, 8]
200. What will be the output of the following Python code?
a) [1, 5, 9]
b) [4, 5, 6]
c) [3, 5, 7]
d) [2, 5, 8]
203. What will be the output of the following Python code?
a) [3, 6, 9, 16, 20, 24, 35, 40, 45]
b) Error
c) [0, 30, 60, 120, 160, 200, 300, 350, 400]
d) 0
204. What will be the output of the following Python code?
a) [11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 20, 30, 40, 50, 60, 70, 80, 90]
b) [10, 20, 30, 40, 50, 60, 70, 80, 90]
c) [11, 12, 13, 14, 15, 16, 17, 18, 19]
d) [0, 10, 20, 30, 40, 50, 60, 70, 80]
205. What will be the output of the following Python code?
a) [0, 30, 60, 120, 160, 200, 300, 350, 400]
b) [[3, 6, 9], [16, 20, 24], [35, 40, 45]]
c) No output
d) Error
206. What will be the output of the following Python code?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
a) Address of the zip object
b) Address of the matrices A and B
c) No output
d) [3, 6, 9, 16, 20, 24, 35, 40, 45]
207. Which of the following is a Python tuple? a) [1, 2, 3]
b) (1, 2, 3)
a) [2, 3, 9]
b) [1, 2, 4, 3, 8, 9]
c) [1, 4, 8]
d) (1, 4, 8)
212. What will be the output of the following Python code?
a) 40
b) 45
216. What will be the output of the following Python code?
a) 30
b) 24
c) 33
d) 12
221. What will be the output of the following Python code?
a) Now, a=(1,2,4)
b) Now, a=(1,3,4)
c) Now a=(3,4)
d) Error as tuple is immutable
222. What will be the output of the following Python code?
a) Too many arguments for sum() method
b) The method sum() doesn’t exist for tuples
c) 12
a) Yes, c will be ((1, ‘A’), (2, ‘B’), (3, ‘C’))
b) Yes, c will be ((1,2,3),(‘A’,’B’,’C’))
c) No because tuples are immutable
d) No because the syntax for zip function isn’t valid
227. Is the following Python code valid?
a) Yes, [1,2,3] is printed
b) No, invalid syntax
c) Yes, (1,2,3) is printed
d) 1 is printed
a) a(i=4, j=7)
b) obj(i=4, j=7)
c) (4,7)
d) An exception is thrown
232. Tuples can’t be made keys of a dictionary.
a) True
b) False
233. Is the following Python code valid?
a) [(1, 2), (2, 4), (3, 9)]
b) [(2,4),(1,2),(3,9)]
c) Error because tuples are immutable
d) Error, tuple has no sort attribute
237. Which of these about a set is not true?
a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type
a) 5 5 6
b) 5 6 7
c) 5 5 6 7 7 7
d) 5 6 7 7 7
241. Which of the following statements is used to create an empty set?
a) { }
b) set()
c) [ ]
d) ( )
242. What will be the output of the following Python code?
a) {4,5,6,2,8}
b) {4,5,6,2,8,6}
c) Error as unsupported operand type for sets
d) Error as the duplicate item 6 is present in both sets
246. What will be the output of the following Python code?
a) {4,5}
b) {6}
c) Error as unsupported operand type for set data type
d) Error as the duplicate item 6 is present in both sets
a) Invalid operation
b) {3, 4, 5, 6, 7}
c) {5}
d) {3,4,6,7}
252. Is the following Python code valid?
c) No, invalid syntax for add method
d) Yes, now a is {5,6,7}
256. Set members must not be hashable.
a) True
b) False
257. What will be the output of the following Python code?
a) Error, no method called update for set data type
b) {1, 2, 3, 4, 5}
c) Error, list can’t be added to set
a) {1,2,3}
b) Error, invalid syntax for add
c) {1,2,3,4}
d) Error, copying of sets isn’t allowed
261. What will be the output of the following Python code?
a) 0
b) {1,2,3,4}
c) {1,2,3}
d) Nothing is printed
d) {8,10}
265. What will be the output of the following Python code?
a) 8
b) Error, unsupported operand ‘+’ for sets
c) 6
d) Nothing is displayed
266. What will be the output of the following Python code?
269. The following Python code results in an error.
s={2, 3, 4, [5, 6]}
a) True
b) False
270. Set makes use of Dictionary makes use of
a) keys, keys
b) key values, keys
c) keys, key values
d) key values, key values
271. Which of the following lines of code will result in an error?
a) s={abs}
b) s={4, ‘abc’, (1,2)}
c) s={2, 2.2, 3, ‘xyz’}
d) s={san}
272. What will be the output of the following Python code?
a) {2, 5, 7}
b) {2, 5, 6, 7}
c) {2, 5, 6, 6, 7}
d) Error
273. Input order is preserved in sets.
a) True
b) False
274. Write a list comprehension for number and its cube for:
a) [x**3 for x in l]
b) [x^3 for x in l]
c) [x**3 in l]
d) [x^3 in l]
275. What will be the output of the following Python code?
a) {1, 2, 3, 4}
b) {1, 2, 4, 3}
c) {4, 1, 2, 3}
d) Error
276. Which of the following functions cannot be used on heterogeneous sets?
d) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
280. What will be the output of the following Python code snippet?
{a**2 for a in range(4)}
a) {1, 4, 9, 16}
b) {0, 1, 4, 9, 16}
c) Error
d) {0, 1, 4, 9}
281. The output of the following code is: class<’set’>.
284. The difference between the functions discard and remove is that:
a) Discard removes the last element of the set whereas remove removes the first element of the set
b) Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element
c) Remove removes the last element of the set whereas discard removes the first element of the set
d) Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element.
285. If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:
a) s2.issubset(s1)
a) True
b) False
c) None
d) Error
290. What will be the output of the following Python code snippet?
a) True
b) False
294. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which
command do we use?
a) d.size()
b) len(d)
c) size(d)
d) d.len()
295. What will be the output of the following Python code snippet?
a) [“john”, “peter”]
b) [“john”:40, “peter”:45]
c) (“john”, “peter”)
d) (“john”:40, “peter”:45)
296. Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?
a) Since “susan” is not a value in the set, Python raises a KeyError exception
b) It is executed fine and no exception is raised, and it returns None
c) Since “susan” is not a key in the set, Python raises a KeyError exception
d) Since “susan” is not a key in the set, Python raises a syntax error
297. Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable
298. Which of the following is not a declaration of the dictionary? a) {1: ‘A’, 2: ‘B’}
b) dict([[1,”A”],[2,”B”]])
c) {1,”A”,2”B”}
d) { }
299. What will be the output of the following Python code snippet?
a) 1 A 2 B 3 C
b) 1 2 3
c) A B C
d) 1:”A” 2:”B” 3:”C”
300. What will be the output of the following Python code snippet?
a) 1
b) A
c) 4
d) Invalid syntax for get method
301. What will be the output of the following Python code snippet?
a) {1: ‘A’, 2: ‘B’, 3: ‘C’}
b) Method update() doesn’t exist for dictionaries
c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
d) {4: ‘D’, 5: ‘E’}
305. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
a) Error, copy() method doesn’t exist for dictionaries
b) {1: ‘A’, 2: ‘B’, 3: ‘C’}
c) {1: ‘A’, 2: ‘D’, 3: ‘C’}
d) “None” is printed
b) 3
c) Too many arguments for pop() method
d) 4
310. What will be the output of the following Python code?
print(i,end=" ")
a) 1 2 3
b) ‘A’ ‘B’ ‘C’
c) 1 ‘A’ 2 ‘B’ 3 ‘C’
d) Error, it should be: for i in a.items():
311. What will be the output of the following Python code?
a) Syntax error
b) dict_items([(‘A’), (‘B’), (‘C’)])
c) dict_items([(1,2,3)])
d) dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
312. Which of the statements about dictionary values if false?
a) More than one key can have the same value
b) The values of the dictionary can be accessed as dict[key]
c) Values of a dictionary must be unique
d) Values of a dictionary can be a mixture of letters and numbers
313. What will be the output of the following Python code snippet?
a) method del doesn’t exist for the dictionary
b) del deletes the values in the dictionary
c) del deletes the entire dictionary
d) del deletes the keys in the dictionary
314. If a is a dictionary with some key-value pairs, what does a.popitem() do?
a) Removes an arbitrary element
b) Removes all the key-value pairs
c) Removes the key-value pair for the key given as an argument
d) Invalid method for dictionary
315. What will be the output of the following Python code snippet?
a) 3
b) 1
c) 2
d) 0
a) 0
b) None
c) 3
d) An exception is thrown
319. What will be the output of the following Python code snippet?
a) 0
b) 2
a) {1,2,3,4}
b) Counter({4, 1, 3, 2})
c) Counter({4: 3, 1: 2, 3: 2, 2: 1})
d) {4: 3, 1: 2, 3: 2, 2: 1}
323. What will be the output of the following Python code snippet?
a) Counter({4: 3, 2: 2, 3: 1})
b) {3:1}
c) {4:3}
d) [(4, 3)]
324. What will be the output of the following Python code snippet?
a) Counter({4: 3, 2: 2, 3: 1})
b) {3:1}
c) {4:3}
d) [(4, 3)]
325. What will be the output of the following Python code snippet?
a) Counter({3: 3, 2: 2, 4: 2})
b) Counter({2: 2, 3: 1, 4: 1})
c) Counter({3: 2})
d) Counter({4: 1})
326. What will be the output of the following Python code snippet?
a) Counter({3: 12, 4: 1, 5: 1})
b) Counter({3: 1, 4: 1, 5: 1})
c) Counter({4: 2})
d) Counter({5: 1})
327. The following Python code is invalid.
a) True
b) False
328. What will be the output of the following Python code?
331. What will be the output of the following Python code?
a) Dictionary comprehension doesn’t exist
b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}
c) {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}
d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
332. What will be the output of the following Python code?
d) {1: ‘a’, 2: ‘b’, 3: ‘c’}
336. What will be the output of the following Python code?
a) An exception is thrown
b) {0: ‘A0’, 1: ‘A1’, 2: ‘A2’, 3: ‘A3’, 4: ‘A4’}
c) {0: ‘A’, 1: ‘A’, 2: ‘A’, 3: ‘A’, 4: ‘A’}
d) {0: ‘0’, 1: ‘1’, 2: ‘2’, 3: ‘3’, 4: ‘4’}
337. What will be the output of the following Python code?
a) 4
b) 0
c) An exception is thrown
d) 7
341. What will be the output of the following Python code?
a) {‘2’:2, ‘0’:0, ‘1’:1}
d) 0
346. What will be the output of the following Python function?
any([2>8, 4>2, 1>2])
a) Error
b) True
c) False
d) 4>2
347. What will be the output of the following Python function?
351. What will be the output of the following Python function?
complex(1+2j)
a) Error
b) 1
c) 2j
d) 1+2j
352. What is the output of the function complex()?
a) 0j
b) 0+0j
c) 0
d) Error
353. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
a) (a%b, a//b)
c) chr()
d) max()
358. Which of the following is the use of function in python?
a) Functions are reusable pieces of programs
b) Functions don’t provide better modularity for your application
c) you can’t also create your own functions
d) All of the mentioned
359. Which keyword is used for function?
a) Fun
b) Define
c) Def
d) Function
360. What will be the output of the following Python code?
a) 3
b) 4
c) 4 is maximum
d) None of the mentioned
361. What will be the output of the following Python code?
a) 2
b) 3
c) The numbers are equal
d) None of the mentioned
362. Which of the following is a feature of DocString?
a) Provide a convenient way of associating documentation with Python modules, functions, classes, and methods
b) All functions should have a docstring
c) Docstrings can be accessed by the doc attribute on objects
d) All of the mentioned
363. Which are the advantages of functions in python?
a) Reducing duplication of code
b) Decomposing complex problems into simpler pieces
c) Improving clarity of the code
d) All of the mentioned
364. What are the two main types of functions?
a) Custom function
b) Built-in function & User defined function
a) 9
b) 3
c) 27
d) 30
370. What is the type of each element in sys.argv?
a) set
b) list
c) tuple
d) string
b) 1 3
c) error
d) none of the mentioned
375. What will be the output of the following Python code?
def foo():
a) 0
b) 1
c) error
d) none of the mentioned
a) [0] [1] [2]
b) [0] [0, 1] [0, 1, 2]
c) [1] [2] [3]
d) [1] [1, 2] [1, 2, 3]
379. What will be the output of the following Python code?
a) Error
b) 12
c) 15
a) Error
b) 12 4
c) 4 12
d) 4 15
383. What will be the output of the following Python code?
a) Error
b) 7
c) 8
d) 15
386. What will be the output of the following Python code?
389. What will be the output of the following Python code?
a) 2
b) 1
c) 0
d) Error
390. On assigning a value to a variable inside a function, it automatically becomes a global variable.
a) True
394. Which of these definitions correctly describes a module?
a) Denoted by triple quotes for providing the specification of certain program elements
b) Design and implementation of specific functionality to be incorporated into a program
c) Defines the specification of how it is to be used
d) Any program that reuses code
395. Which of the following is not an advantage of using modules?
a) Provides a means of reuse of program code
b) Provides a means of dividing up tasks
c) Provides a means of reducing the size of the program
d) Provides a means of testing individual parts of the program
396. Program code making use of a given module is called a of the module.
a) Client
b) Docstring
c) Interface
d) Modularity
397. is a string literal denoted by triple quotes for providing the specifications of certain program elements.
a) Interface
b) Modularity
c) Client
d) Docstring
398. Which of the following is true about top-down design process?
a) The details of a program design are addressed before the overall design
b) Only the details of the program are addressed
c) The overall design of the program is addressed before the details
d) Only the design of the program is addressed
399. In top-down design every module is broken into same number of submodules.
a) True
b) False
400. Which of the following isn’t true about main modules?
a) When a python file is directly executed, it is considered main module of a program
b) Main modules may import any number of modules
c) Special name given to main modules is: main
d) Other main modules can import main modules
401. Which of the following is not a valid namespace?
a) Global namespace
b) Public namespace
c) Built-in namespace
d) Local namespace
402. Which of the following is false about “import modulename” form of import?
a) The namespace of imported module becomes part of importing module
b) This form of import prevents name clash
c) The namespace of imported module becomes available to importing module
d) The identifiers in module are accessed as: modulename.identifier
403. Which of the following is false about “from-import” form of import?
a) The syntax is: from modulename import identifier
b) This form of import prevents name clash
c) The namespace of imported module becomes part of importing module
d) The identifiers in module are accessed directly as: identifier
404. Which of the statements about modules is false?
a) In the “from-import” form of import, identifiers beginning with two underscores are private and aren’t imported
b) dir() built-in function monitors the items in the namespace of the main module
c) In the “from-import” form of import, all identifiers regardless of whether they are private or public are imported
d) When a module is loaded, a compiled version of the module with file extension .pyc is automatically produced
405. What will be the output of the following Python code?
a) 120
b) Nothing is printed
c) Error, method factorial doesn’t exist in math module
d) Error, the statement should be: print(factorial(5))
406. What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the global namespace, then the local namespace and finally the built-in namespace
b) Python first searches the local namespace, then the global namespace and finally the built-in namespace
c) Python first searches the built-in namespace, then the global namespace and finally the local namespace
d) Python first searches the built-in namespace, then the local namespace and finally the global namespace.
407. Which of the following functions can help us to find the version of python that we are currently working on?
a) sys.version
b) sys.version()
c) sys.version(0)
d) sys.version(1)
408. Which of the following functions is not defined under the sys module?
a) sys.platform
b) sys.path
c) sys.readline
d) sys.argv
409. The output of the functions len(“abc”) and sys.getsizeof(“abc”) will be the same.
a) True
b) False
410. What will be the output of the following Python code, if the sys module has already been imported?
a) helloworld
b) hello world10
c) hello world11
d) error
411. What will be the output of the following Python code?
a) India5
b) India
c) ‘India\n’
d) ‘India
412. To obtain a list of all the functions defined under sys module, which of the following functions can be used?
a) print(sys)
b) print(dir.sys)
c) print(dir[sys])
d) print(dir(sys))
413. The output of the function len(sys.argv) is
a) Error
b) 1
c) 0
d) Junk value
414. What is returned by math.ceil(3.4)?
a) 3
b) 4
c) 4.0
d) 3.0
415. What is the value returned by math.floor(3.4)?
a) 3
b) 4
c) 4.0
d) 3.0
416. What is displayed on executing print(math.fabs(-3.4))? a) -3.4
b) 3.4
c) 3
d) -3
417. Is the output of the function abs() the same as that of the function math.fabs()?
a) sometimes
b) always
c) never
d) none of the mentioned
418. What is the value of x if x = math.factorial(0)?
a) 0
b) 1
c) error
d) none of the mentioned
419. What will be the output of print(math.factorial(4.5))?
a) 24
b) 120
c) error
d) 24.0
420. What does the function math.frexp(x) return?
a) a tuple containing the mantissa and the exponent of x
b) a list containing the mantissa and the exponent of x
c) a tuple containing the mantissa of x
d) a list containing the exponent of x
421. What is the result of math.fsum([.1 for i in range(20)])? a) 2.0
b) 20
c) 2
d) 2.0000000000000004
422. What is returned by math.isfinite(float(‘inf’))?
a) True
b) False
c) None
d) error
423. What is returned by math.isfinite(float(‘nan’))?
a) True
b) False
c) None
d) error
424. What is x if x = math.isfinite(float(‘0.0’))?
a) True
b) False
c) None
d) error
425. What will be the output of the following Python code?
a) error, the minus sign shouldn’t have been inside the brackets
b) error, there is no function called isinf
c) True
d) False
426. What is returned by math.modf(1.0)? a) (0.0, 1.0)
b) (1.0, 0.0)
c) (0.5, 1)
d) (0.5, 1.0)
427. represents an entity in the real world with its identity and behaviour.
a) A method
b) An object
c) A class
d) An operator
428. is used to create an object.
a) class
b) constructor
c) User-defined functions
d) In-built functions
429. What will be the output of the following Python code?
class test:
a) The program has an error because constructor can’t have default arguments
b) Nothing is displayed
a) Runs normally, doesn’t display anything
b) Displays 0, which is the automatic default value
c) Error as one argument is required while creating the object
d) Error as display function requires additional argument
434. Is the following Python code correct?
a) 12
b) 52
c) 13
d) 60
a) It isn’t as the object declaration isn’t right
b) It isn’t as there isn’t any init method for initializing class members
c) Yes, this method of calling is called unbounded method call
d) Yes, this method of calling is called bounded method call
442. What are the methods which begin and end with two underscore characters called?
a) Special methods
b) In-built methods
c) User-defined methods
d) Additional methods
443. What will be the output of the following Python code?
446. What will be the output of the following Python code?
a) Error as age isn’t defined
b) True
c) False
d) 7
450. Which of the following best describes inheritance?
a) Ability of a class to derive members of another class as a part of its own definition
b) Means of bundling instance variables and methods in order to restrict access to certain class members
c) Focuses on variables and passing of variables to functions
d) Allows for implementation of elegant software that is well designed and easily modified
451. Which of the following statements is wrong about inheritance?
a) Protected members of a class can be inherited
b) The inheriting class is called a subclass
c) Private members of a class can be inherited and accessed
d) Inheritance is one of the features of OOP
452. What will be the output of the following Python code?
455. When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used.
a) True
b) False
456. Suppose B is a subclass of A, to invoke the init method in A from B, what is the line of code you should write?
a) A. init (self)
b) B. init (self)
c) A. init (B)
d) B. init (A)
457. What will be the output of the following Python code?
d) 1 2
459. What does built-in function type do in context of classes?
a) Determines the object name of any value
b) Determines the class name of any value
c) Determines class description of any value
d) Determines the file name of any value
460. Which of the following is not a type of inheritance?
a) Double-level
b) Multi-level
c) Single-level
d) Multiple
461. What does built-in function help do in context of classes?
a) Determines the object name of any value
b) Determines the class identifiers of any value
a) Multi-level inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Single-level inheritance
464. What type of inheritance is illustrated in the following Python code?
a) Multi-level inheritance
a) A non-private method in a superclass can be overridden
b) A derived class is a subset of superclass
c) The value of a private variable in the superclass can be changed in the subclass
d) When invoking the constructor from a subclass, the constructor of superclass is automatically invoked
468. What will be the output of the following Python code?
a) True
b) False
472. What will be the output of the following Python code?
a) 1
b) 0
c) Error, invalid syntax for object declaration
a) 5
b) Error, class member x has two values
c) 3
d) Error, protected class member can’t be accessed in a subclass
475. Which of the following best describes polymorphism?
a) Ability of a class to derive members of another class as a part of its own definition
b) Means of bundling instance variables and methods in order to restrict access to certain class members
c) Focuses on variables and passing of variables to functions
d) Allows for objects of different types and behaviour to be treated as the same general type
479. What will be the output of the following Python code?
a) 11
b) 2
483. What will be the output of the following Python code?
a) 15
b) 60
c) An exception is thrown
a) 15
b) 30
c) An exception is thrown
d) 60
486. What will be the output of the following Python code?
a) A
b) An exception is thrown
c) A B
d) B
489. Which of the following statements is true?
a) A non-private method in a superclass can be overridden
b) A subclass method can be overridden by the superclass
c) A private method in a superclass can be overridden
d) Overriding isn’t possible in Python
490. To open a file c:\scores.txt for reading, we use
a) infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)
491. To open a file c:\scores.txt for writing, we use
a) outfile = open(“c:\scores.txt”, “w”)
b) outfile = open(“c:\\scores.txt”, “w”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
492. To open a file c:\scores.txt for appending data, we use
a) outfile = open(“c:\\scores.txt”, “a”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
493. Which of the following statements are true?
a) When you open a file for reading, if the file does not exist, an error occurs
b) When you open a file for writing, if the file does not exist, a new file is created
c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file
d) All of the mentioned
494. To read two characters from a file object infile, we use
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
495. To read the entire remaining contents of the file as a string from a file object infile, we use
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
496. What will be the output of the following Python code?
a) True
b) False
c) None
d) Error
497. To read the next line of the file from a file object infile, we use
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
498. To read the remaining lines of the file from a file object infile, we use
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
499. The readlines() method returns
a) str
b) a list of lines
c) a list of single characters
d) a list of integers
500. Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?
a) Raw_input & Input
b) Input & Scan
c) Scan & Scanner
d) Scanner
501. Which one of the following is not attributes of file?
a) closed
b) softspace
c) rename
d) mode
502. What is the use of tell() method in python?
a) tells you the current position within the file
b) tells you the end position within the file
c) tells you the file is opened or not
d) none of the mentioned
503. What is the current syntax of rename() a file?
a) rename(current_file_name, new_file_name)
506. What is the use of seek() method in files?
a) sets the file’s current position at the offset
b) sets the file’s previous position at the offset
c) sets the file’s current position within the file
d) none of the mentioned
507. What is the use of truncate() method in file?
a) truncates the file size
b) deletes the content of the file
c) deletes the file size
d) none of the mentioned
508. Which is/are the basic I/O connections in file?
a) Standard Input
b) Standard Output
c) Standard Errors
d) All of the mentioned
509. Which of the following mode will refer to binary data?
a) r
b) w
c) +
d) b
510. What is the pickling?
a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned
511. What is unpickling?
a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned
512. What is the correct syntax of open() function?
a) file = open(file_name [, access_mode][, buffering])
b) file object = open(file_name [, access_mode][, buffering])
c) file object = open(file_name)
d) none of the mentioned
513 What will be the output of the following Python code?
a) Compilation Error
b) Runtime Error
c) No Output
d) Flushes the file when closing them
514. Correct syntax of file.writelines() is?
a) file.writelines(sequence)
b) fileObject.writelines()
c) fileObject.writelines(sequence)
d) none of the mentioned
515. Correct syntax of file.readlines() is?
a) fileObject.readlines( sizehint );
a) no, there is no such thing as else
b) no, else cannot be used with except
c) no, else must come before except
d) yes
520. Is the following Python code valid?
b) 2
c) 3
d) error, there is more than one return statement in a single try-finally block
524. What will be the output of the following Python code?
a) 1 2
b) 1
c) 2
d) none of the mentioned
a) Assertion Error
b) 10 8
c) No output
d) 108
529. What will be the output of the following Python code?
a) 8
b) 9
a) ‘list’ object is not iterator
b) ‘tuple’ object is not iterator
c) ‘list’ object is iterator
d) ‘tuple’ object is iterator
533. Which of the following is not an exception handling keyword in Python?
a) try
b) except
c) accept
D. module
538. If return statement is not used inside the function, the function will return:
A. None
B. 0
C. Null
D. Arbitary value
539. What is a recursive function?
543. The output of executing string.ascii_letters can also be achieved by:
a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) string.letters
d) string.lowercase_string.upercase
544. What will be the output of the following Python code?
a) olleh
b) hello
c) h
d) o
545. What arithmetic operators cannot be used with strings?
a) +
b) *
c) –
d) All of the mentioned
546. What will be the output of the following Python code?
1. >>>print (r"\nhello")
a) a new line and hello
b) \nhello
c) the letter r and then hello
d) error
547. What will be the output of the following Python statement?
1. >>>print('new' 'line')
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line
548. What will be the output of the following Python code?
a) dlrowolleh
b) hello
c) world
d) helloworld
549. What will be the output of the following Python code?
print(0xA + 0xB + 0xC)
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33
550. What will be the output of the following Python code?
a) wo
b) world
c) sn
d) rl
553. What will be the output of the following Python code?
a) snow
b) snow world
c) Error
b) 4
c) 3
d) 1
558. What will be the output of the following Python code?
a) dlrowolleh
b) True
c) -1
d) None
559. What will be the output of the following Python code?
a) -1
b) 4
c) 3
d) 1
560. What will be the output of the following Python code?
a) dlrowolleh
b) True
c) -1
d) None
561. What will be the output of the following Python code?
a) dlrowolleh
b) True
c) -1
d) None
562 To concatenate two strings to a third what statements are applicable?
a) s3 = s1 . s2
b) s3 = s1.add(s2)
c) s3 = s1. add (s2)
d) s3 = s1 * s2
563. What will be the output of the following Python statement?
1.>>>chr(ord('A'))
a) A
b) B
c) a
d) Error
564. What will be the output of the following Python statement?
1.>>>print(chr(ord('b')+1))
a) DCBA
b) A, B, C, D
c) D C B A
d) D, C, B, A will be displayed on four lines
570. What will be the output of the following Python statement?(python 3.xx)
(Note that the number of blank spaces before the number is 5)
a) -12345.0 (5 blank spaces before the number)
b) -12345.0
c) Error
d) -12345.000000000…. (infinite decimal places)
576. Which of the following functions will not result in an error when no arguments are passed to it?
a) min()
b) divmod()
c) all()
d) float()
a) 48
b) 14
c) 64
d) None of the mentioned
582. What will be the output of the following Python code?
a) Arthur Sir
b) Sir Arthur
c) Arthur
d) None of the mentioned
588. What will be the output of the following Python code?
a) 9997
b) 9999
c) 9996
d) None of the mentioned
589. In file handling, what does this terms means “r, a”?
a) read, append
b) append, read
c) write, append
d) none of the mentioned
590. What is the use of “w” in file handling?
a) Read
b) Write
c) Append
d) None of the mentioned
591. What is the use of “a” in file handling?
a) Read
b) Write
c) Append
d) None of the mentioned
592. Which function is used to read all the characters?
a) Read()
b) Readcharacters()
c) Readall()
d) Readchar()
593. Which function is used to read single line from file?
a) Readline()
b) Readlines()
c) Readstatement()
d) Readfullline()
594. Which function is used to read single line from file?
a) Readline()
b) Readlines()
c) Readstatement()
d) Readfullline()
595. Which function is used to write all the characters?
a) write()
b) writecharacters()
c) writeall()
d) writechar()
596. Which function is used to write a list of string in a file?
a) writeline()
b) writelines()
c) writestatement()
d) writefullline()
597. Which function is used to close a file in python?
a) Close()
b) Stop()
c) End()
d) Closefile()
598. Is it possible to create a text file in python?
a) Yes
b) No
c) Machine dependent
d) All of the mentioned
599. Which of the following are the modes of both writing and reading in binary format in file?
a) wb+
b) w
c) wb
d) w+
600. What is the result of cmp(3, 1)?
a) 1
b) 0
c) True
d) False
601. What happens if the file is not found in the following Python code?
a) No error
605. What will be the output of the following Python code?
int('65.43')
a) ImportError
b) ValueError
c) TypeError
d) NameError
606. Compare the following two Python codes shown below and state the output if the input entered in each case is -6?
a) Bye (printed once)
b) No output
c) Invalid (printed once)
d) Bye (printed infinite number of times)
609. Identify the type of error in the following Python codes?
a) Syntax, Syntax
b) Semantic, Syntax
c) Semantic, Semantic
d) Syntax, Semantic
610. Which of the following statements is true?
a) The standard exceptions are automatically imported into Python programs
b) All raised standard exceptions must be handled in Python
c) When there is a deviation from the rules of a programming language, a semantic error is thrown
d) If any exception is thrown in try block, else block is executed
611. Which of the following is not a standard exception in Python?
a) NameError
b) IOError
c) AssignmentError
d) ValueError
612. Syntax errors are also known as parsing errors.
a) True
b) False
613. An exception is
a) an object
b) a special function
c) a standard module
d) a module
614. exceptions are raised as a result of an error in opening a particular file.
a) ValueError
b) TypeError
c) ImportError
d) IOError
615. Which of the following blocks will be executed whether an exception is thrown or not?
a) except
b) else
c) finally
d) assert
616. Which of these is not a fundamental features of OOP?
a) Encapsulation
b) Inheritance
c) Instantiation
d) Polymorphism
617. Which of the following is the most suitable definition for encapsulation?
a) Ability of a class to derive members of another class as a part of its own definition
a) The program has an error because there isn’t any function to return self.a
b) The program has an error because b is private and display(self) is returning a private member
c) The program has an error because b is private and hence can’t be printed
d) The program runs fine and 1 is printed
622. Methods of a class that provide access to private members of the class are called as
and
a) The program runs properly and prints 45
b) The program has an error because the value of members of a class can’t be changed from outside the class
c) The program runs properly and prints 1
d) The program has an error because the value of members outside a class can only be changed as self.a=45
625. Private members of a class cannot be accessed.
a) True
b) False
626. The purpose of name mangling is to avoid unintentional access of private class members.
a) True
b) False
627. What will be the output of the following Python code?
a) The program has an error because display() is trying to print a private class member
b) The program runs fine but nothing is printed
c) The program runs fine and 5 is printed
d) The program has an error because display() can’t be accessed
628. What will be the output of the following Python code?
a) The program runs fine and 8.7 is printed
b) Error because private class members can’t be accessed
c) Error because the proper syntax for name mangling hasn’t been implemented
d) The program runs fine but nothing is printed
629. Which of the following is false about protected class members?
a) They begin with one underscore
b) They can be accessed by subclasses
c) They can be accessed by name mangling method
d) They can be accessed within a class
630. What will be the output of the following Python code?
a) Error
b) [1, 0, 2, 0, ‘hello’, ”, []]
c) [1, 0, 2, ‘hello’, ”, []]
d) [1, 2, ‘hello’]
634. What will be the output of the following Python code?
a) pass
b) true
b) False
c) Error
d) No output
638. What is a variable defined outside a function referred to as?
a) A static variable
b) A global variable
c) A local variable
d) An automatic variable
640. What is a variable defined inside a function referred to as?
a) A global variable
b) A volatile variable
c) A local variable
643. What will be the output of the following Python code?
a) An exception is thrown because of conflicting values
b) 1 2
c) 3 3
d) 3 2
644. What will be the output of the following Python code?
a) String
b) Tuple
c) Dictionary
d) An exception is thrown
648. What will be the output of the following Python code?
a) [0]
b) [1]
c) [1, 0]
d) [0, 1]
649. How are variable length arguments specified in the function heading?
a) one star followed by a valid identifier
b) one underscore followed by a valid identifier
c) two stars followed by a valid identifier
d) two underscores followed by a valid identifier
650. Which module in the python standard library parses options received from the command line?
a) getopt
b) os
c) getarg
d) main
651. What is the type of sys.argv?
a) set
b) list
c) tuple
d) string
652. What is the value stored in sys.argv[0]?
a) null
b) you cannot access it
c) the program’s name
d) the first argument
653. How are default arguments specified in the function heading?
a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (“)
c) identifier followed by the default value within square brackets ([])
d) identifier
654. How are required arguments specified in the function heading?
a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (“)
c) identifier followed by the default value within square brackets ([])
d) identifier
655. What will be the output of the following Python code?
658. What will be the output of the following Python code?
a) [‘AB’, ‘CD’]
b) [‘ab’, ‘cd’]
c) error
d) none of the mentioned
682. Which of the following is not a valid mode to open a file?
a) ab
b) rw
c) r+
d) w+
683. What is the difference between r+ and w+ modes?
a) no difference
b) os.rename(existing_name, new_name)
c) os.rename(fp, new_name)
d) os.set_name(existing_name, new_name) 689. How do you delete a file?
a) del(fp)
b) fp.delete()
c) os.remove(‘file’)
d) os.delete(‘file’)
690. How do you change the file position to an offset value from the start?
a) fp.seek(offset, 0)
b) fp.seek(offset, 1)
c) fp.seek(offset, 2)
d) none of the mentioned
691. What happens if no arguments are passed to the seek function?
a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error
692. Which module in Python supports regular expressions?
a) re
b) regex
c) pyregex
d) none of the mentioned
693. Which of the following creates a pattern object?
a) re.create(str)
b) re.regex(str)
c) re.compile(str)
d) re.assemble(str)
694. What does the function re.match do?
a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
d) none of the mentioned
4. What does the function re.search do?
a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
d) none of the mentioned
695. What is “Hello”.replace(“l”, “e”)?
a) Heeeo
b) Heelo
c) Heleo
d) None
696. To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
a) i. add(j)
b) i. add (j)
c) i. Add(j)
d) i. ADD(j)
Comments
Post a Comment