-
Notifications
You must be signed in to change notification settings - Fork 38
/
quiz.txt
310 lines (261 loc) · 7.79 KB
/
quiz.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
1) Which of these programming paradigms does Python support?
a) structured
b) object-oriented
c) functional
d) all of the above
d
2) How would you specify literal characters `{` and `}` in f-strings?
a) `{{` and `}}` respectively
b) `\{` and `\}` respectively
a
3) If you define a function with arguments as `total(n1, n2)`, can you still call this function using keywords, for example `total(n2=5, n1=100)`?
a) False
b) True
b
4) Given a sequence object named `seq` and a positive integer `n`, which of these is equivalent to `seq[-n]`?
a) `seq[len(seq) - n + 1]`
b) `seq[len(seq) - n - 1]`
c) `seq[len(seq) - n]`
c
5) Given a dict object named `fruits` and you have a loop `for k in fruits`, what does `k` get in each iteration?
a) key
b) value
c) key-value pair as a tuple object
a
6) Unary operators `+`, `-` and `~` have higher precedence over the multiplication `*` operator?
a) True
b) False
a
7) What would be the output for `int(' \t 3a ', 16)`?
a) ValueError: invalid literal for int() with base 16: ' \t 3a '
b) 58
c) 3
b
8) If you use the `return` keyword without an expression:
a) `None` value is used as the default
b) you'll get SyntaxError
c) you'll get runtime exception
a
9) Which command would you use to view the entire contents of the current function code with `pdb`?
a) f
b) ll
c) c
d) p
b
10) Given two set objects `set1` and `set2`, what would be the equivalent for `set1 ^ set2`?
a) `(set2 - set1) | (set1 - set2)`
b) `set1.symmetric_difference(set2)`
c) Both a) and b)
c
11) Which of these statements would you use if you want to define a placeholder function which does nothing?
a) `none`
b) `pass`
c) `nop`
d) Both a) and b)
b
12) Which of these statements is correct?
a) `from math import fact=factorial`
b) `from math import factorial as fact`
c) Both a) and b)
b
13) By executing the code `*a, b = (*(1, 2), 3, *(4, 5))` you'll get:
a) SyntaxError
b) a = [1, 2, 3, 4] and b = 5
c) a = 1 and b = [2, 3, 4, 5]
d) a = (1, 2, 3, 4) and b = 5
b
14) Which of these built-in functions support the `key` argument to provide a custom function?
a) `sorted()`
b) `min()`
c) `max()`
d) all of the above
d
15) Which of these values can be used as a dict key or as a set element?
a) (1, 2)
b) [1, 2, 3]
c) Both a) and b)
a
16) Which of these is a valid integer value?
a) `100`
b) `0x1F`
c) `2_3_4_5`
d) all of the above
d
17) Given `nums = [1, 4, 6, 22, 3, 5]`, which of these is NOT a valid list operation?
a) `nums[1:4] = [-100]`
b) `nums[-2:] = 'hello'`
c) `nums += ('a', 'b')`
d) `nums += 100`
d
18) Given `fruit = 'apple'`, which of these will give you a TypeError prior to Python version 3.13?
a) `fruit.replace('p', 'a', count=1)`
b) `fruit.replace('p', 'a', 1)`
c) `fruit.replace('p', 'WXYZ')`
a
19) The default mode for the built-in function `open()` is:
a) `rt` (read text mode)
b) `rb` (read binary mode)
a
20) Which of these can be a valid value for `sys.argv[0]`?
a) name of the Python script
b) -c
c) empty string
d) all of the above
d
21) Which string syntax allows you to embed expressions within `{}`?
a) single quoted
b) double quoted
c) raw strings
d) format strings
e) all of the above
d
22) Which of these is the correct order of usage with `range()` function and sequence slicing?
a) start, stop and step
b) start, step and stop
c) step, start and stop
a
23) Which of these is true?
a) every iterator is also an iterable
b) every iterable is also an iterator
c) Both a) and b)
a
24) Which built-in function helps you to get the codepoint of a character?
a) `codepoint()`
b) `chr()`
c) `ord()`
c
25) Which of these built-in features can be used to capture the output of an external command?
a) `os.popen()`
b) `os.output()`
c) `subprocess.check_output()`
d) Both a) and c)
d
26) `num > 10 and num <= 20` is same as:
a) `10 < num <= 20`
b) `20 >= num > 10`
c) Both a) and b)
c
27) What's the default exception raised by raise if there's no active exception?
a) RuntimeError
b) AssertionError
a
28) Which built-in function would you use to iterate over two or more iterables simultaneously?
a) `parallel()`
b) `zip()`
c) `iter()`
b
29) What does this function definition `def myfunc(**myargs)` do?
a) accepts arbitrary positional arguments
b) accepts arbitrary keyword arguments
c) Both a) and b)
b
30) Which of the following is the correct way to join a list of string values?
a) `['hi', 'bye'].join('-')`
b) `'-'.join(['hi', 'bye'])`
c) Both a) and b)
b
31) What will be the output for `print(r'\')` and `print(r'\\')`?
a) SyntaxError and \\
b) \ and \\
c) \ for both
a
32) Is it valid to combine more than one string prefix such as `b`, `r` and `f`? For example, what would be the output for `print(rf'C:\\quest{name}')` given `name = '\todo\ip.txt'`?
a) SyntaxError
b) C:\\quest\todo\ip.txt
c) C:\\quest odo\ip.txt
c
33) What would happen if you call a function before it is defined?
a) NameError
b) function gets called
c) TypeError
a
34) What would happen if you use the `<` or `<=` or `>` or `>=` operators between numeric and string values?
a) Number will be converted to string
b) String will be converted to number
c) TypeError
c
35) The current working directory has an empty file named `math.py`. What will you get if you execute `print(math.pi)` after importing the `math` module?
a) 3.141592653589793
b) AttributeError: module 'math' has no attribute 'pi'
b
36) Given `chars = tuple('hello')`, what'd you get for `print(chars[0])` and `chars[0] = 'H'`?
a) h and TypeError
b) TypeError and TypeError
a
37) Given `primes = [2, 3, 5, 7, 11]`, what'd you get for `primes[5]` or `primes[-6]`?
a) IndexError: list index out of range
b) 11
c) 2
a
38) Given `primes = [2, 3, 5, 7, 11]`, what'd you get for `primes[:5]` or `primes[-6:]`?
a) IndexError: list index out of range
b) [2, 3, 5, 7, 11]
c) [11, 7, 5, 3, 2]
d) []
b
39) Given `nums = (1, 2)`, will `(a, b, c) = nums` or `(*a, *b) = nums` raise an exception?
a) both are valid
b) you'll get ValueError and SyntaxError respectively
c) first one is valid
d) second one is valid
b
40) Given `nums = [42, 3]`, which of these statements will update `nums` to `[42, 3, 5]`?
a) `nums += 5`
b) `nums += [5]`
c) both a) and b)
d) both a) and b) are invalid
b
41) Given `nums = ([1, 2], 'a', 3)`, what'd you get for `nums[0][0] = 'apple'` followed by `nums[1] = 'fig'`?
a) TypeError and TypeError
b) `(['apple', 2], 'a', 3)` and `(['apple', 2], 'fig', 3)`
c) `(['apple', 2], 'a', 3)` and TypeError
d) TypeError and `([1, 2], 'fig', 3)`
c
42) Given `d = dict(cat=12, dog=5, rat=10, bat=100)`, what'd you get for `a, *b, c = d`?
a) `a = 'cat'`, `b = ['dog', 'rat']` and `c = 'bat'`
b) ValueError
c) SyntaxError
d) `a = ('cat', 12)`, `b = [('dog', 5), ('rat', 10)]` and `c = ('bat', 100)`
a
43) Given `nums = [1, 4, 6, 22, 3, 5, 4, 3, 6, 2, 1, 3, 1]`, what'd you get for `list(dict.fromkeys(nums))`?
a) ValueError
b) SyntaxError
c) `[1, None, 4, None, 6, None, 22, None, 3, None, 5, None, 2, None]`
d) `[1, 4, 6, 22, 3, 5, 2]`
d
44) What'd be the output for `set([3, 2, 3.0]) == {3, 2}`?
a) True
b) False
a
45) What'd you get for `'fig'.join('apple', 'banana')` and `'fig'.join(('apple', 'banana'))`?
a) `'applefigbanana'` and `'applefigbanana'`
b) `'figapplebanana'` and `'figapplebanana'`
c) TypeError and `'applefigbanana'`
d) TypeError and `'figapplebanana'`
c
46) What'd you get for `'na naanana'.removesuffix('na')` and `'na naanana'.rstrip('na')`?
a) `'na naa'` and `'na '`
b) `'na naana'` and `'na '`
c) `'na naana'` and `' '`
d) `'na naa'` and `' '`
b
47) Which string method will help you change `'thIs iS a saMple StrIng'` to `This Is A Sample String`?
a) `title()`
b) `capitalize()`
c) `swapcase()`
a
48) What'd be the output for `'phototonic'.count('oto')`?
a) 2
b) 1
c) 0
b
49) Given `nums = [1, 4, 6, 22, 3]`, what'd you get for `(n * n for n in nums)`?
a) tuple comprehension
b) SyntaxError
c) generator expression
c
50) Which built-in module has a provision to edit a file in-place?
a) `fileinput`
b) `sys`
c) `pathlib`
a