Nucleus Previous Years Solved Sample Placement Papers
-
What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]: print(i, end=' ')
A. 4 3 2 1 Answer: Option A
B. error
C. 1 2 3 4
D. none of the mentioned
-
Solution:
[::-1]
reverses the list. -
What will be the output of the following Python statement?
>>> "a" + "bc"
A. bc
B. abc Answer: Option B
C. a
D. bca
-
Solution:
+
operator is concatenation operator. -
Which function is called when the following Python program is executed?
f = foo() format(f)
A. str()
B. format()
C. __str__()
D. __format__()
-
Solution: The function
__format__()
is called when theformat()
function is used. -
What will be the output of the following Python code?
class tester: def __init__(self, id): self.id = str(id) id = "224" >>> temp = tester(12) >>> print(temp.id)
A. 12 Answer: Option A
B. 224
C. None
D. Error
-
Solution:
Id
in this case will be the attribute of the instance. -
What will be the output of the following Python program?
def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
A. Error
B. None
C. False
D. True Answer: Option D
- Solution: The same object is modified in the function.
-
Which module in the Python standard library parses options received from the command line?
A. getarg
B. getopt Answer: Option B
C. main
D. os
-
Solution:
getopt
parses options received from the command line. -
What will be the output of the following Python program?
z = set('abc') z.add('san') z.update(set(['p', 'q'])) z
A. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
B. {‘abc’, ‘p’, ‘q’, ‘san’}
C. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’} Answer: Option C
D. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san’}
-
Solution: The code shown first adds the element ‘san’ to the set
z
. The setz
is then updated and two more elements, namely, ‘p’ and ‘q’ are added to it. Hence the output is: {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}. -
What arithmetic operators cannot be used with strings in Python?
A. *
B. – Answer: Option B
C. +
D. All of the mentioned
-
Solution:
+
is used to concatenate and*
is used to multiply strings.