Nucleus Previous Years Solved Sample Placement Papers
-
What will be the output of the following Python code?
print("abc. DEF".capitalize())
A. Abc. def Answer: Option A
B. abc. def
C. Abc. Def
D. ABC. DEF
- Solution: The capitalize() function converts the first character of the string to uppercase and the rest to lowercase.
-
Which of the following statements is used to create an empty set in Python?
A. ()
B. []
C. { }
D. set() Answer: Option D
- Solution: {} creates an empty dictionary, while set() creates an empty set.
-
What will be the value of ‘result’ in the following Python program?
list1 = [1,2,3,4] list2 = [2,4,5,6] list3 = [2,6,7,8] result = list() result.extend(i for i in list1 if i not in (list2+list3) and i not in result) result.extend(i for i in list2 if i not in (list1+list3) and i not in result) result.extend(i for i in list3 if i not in (list1+list2) and i not in result)
A. [1, 3, 5, 7, 8] Answer: Option A
B. [1, 7, 8]
C. [1, 2, 4, 7, 8]
D. Error
- Solution: The code generates a list containing elements unique to only one of the input lists. Hence, the result is [1, 3, 5, 7, 8].
-
To add a new element to a list we use which Python command?
A. list1.addEnd(5)
B. list1.addLast(5)
C. list1.append(5) Answer: Option C
D. list1.add(5)
- Solution: The append() function is used to add an element to the end of a list in Python.
-
What will be the output of the following Python code?
print('*', "abcde".center(6), '*', sep='')
A. * abcde *
B. *abcde * Answer: Option B
C. * abcde*
D. * abcde *
- Solution: The center() function pads the string symmetrically, but when the final length is even, padding is added to the right first.
-
What will be the output of the following Python code?
list1 = [1, 3] list2 = list1 list1[0] = 4 print(list2)
A. [1, 4]
B. [1, 3, 4]
C. [4, 3] Answer: Option C
D. [1, 3]
- Solution: Lists in Python are mutable and assignment results in both variables referring to the same list. Changes made via one reference affect the other.
-
Which one of the following is the use of functions in Python?
A. Functions don’t provide better modularity for your application
B. You can’t also create your own functions
C. Functions are reusable pieces of programs Answer: Option C
D. All of the mentioned
- Solution: Functions allow you to organize code into reusable blocks, making applications more modular and easier to maintain.
-
Which of the following Python statements will result in the output: 6?
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
A. A[2][1]
B. A[1][2] Answer: Option B
C. A[3][2]
D. A[2][3]
- Solution: A[1][2] refers to the second row and third column, which contains the value 6.