Explore topic-wise MCQs in Technical Programming.

This section includes 1007 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.

401.

What is the output of the following? def to_upper(k): return k.upper() x = ['ab', 'cd'] print(list(map(to_upper, x)))

A. [‘AB’, ‘CD’].
B. [‘ab’, ‘cd’].
C. none of the mentioned
D. error
Answer» B. [‘ab’, ‘cd’].
402.

What is the output of the following? def to_upper(k): return k.upper() x = ['ab', 'cd'] print(list(map(upper, x)))

A. [‘AB’, ‘CD’].
B. [‘ab’, ‘cd’].
C. none of the mentioned
D. error
Answer» E.
403.

What is the output of the following? x = ['ab', 'cd'] print(list(map(upper, x)))

A. [‘AB’, ‘CD’].
B. [‘ab’, ‘cd’].
C. error
D. none of the mentioned
Answer» D. none of the mentioned
404.

What is the output of the following? elements = [0, 1, 2] def incr(x): return x+1 print(list(map(incr, elements)))

A. [1, 2, 3].
B. [0, 1, 2].
C. error
D. none of the mentioned
Answer» B. [0, 1, 2].
405.

What is the output of the following? elements = [0, 1, 2] def incr(x): return x+1 print(list(map(elements, incr)))

A. [1, 2, 3].
B. [0, 1, 2].
C. error
D. none of the mentioned
Answer» D. none of the mentioned
406.

What is the output of the line of code shown below? list(map((lambda x:x**2), filter((lambda x:x%2==0), range(10))))

A. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
B. [0, 4, 16, 36, 64]
C. Error
D. No output
Answer» C. Error
407.

What is the output of the line of code shown below? list(map((lambda x:x^2), range(10)))

A. [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
B. Error
C. [2, 3, 0, 1, 6, 7, 4, 5, 10, 11]
D. No output
Answer» D. No output
408.

The single line equivalent of the code shown below is: l=[1, 2, 3, 4, 5] def f1(x): return x

A. filter(lambda x:x<0, l)
B. filter(lambda x, y: x<0, l)
C. filter(reduce x<0, l)
D. reduce(x: x<0, l)
Answer» B. filter(lambda x, y: x<0, l)
409.

Which of the following numbers will not be a part of the output list of the code shown below? def sf(a): return a%3!=0 and a%5!=0 m=filter(sf, range(1, 31)) print(list(m))

A. 1
B. 29
C. 6
D. 10
Answer» E.
410.

What is the output of the code shown? m=reduce(lambda x: x-3 in range(4, 10)) print(list(m))

A. [1, 2, 3, 4, 5, 6, 7]
B. No output
C. [1, 2, 3, 4, 5, 6]
D. Error
Answer» C. [1, 2, 3, 4, 5, 6]
411.

What is the output of the code shown below? l=[n for n in range(5)] f=lambda x:bool(x%2) print(f(3), f(1)) for i in range(len(l)): if f(l[i]): del l[i] print(i)

A. True True 1 2 Error
B. False False 1 2
C. True False 1 2 Error
D. False True 1 2
Answer» B. False False 1 2
412.

What is the output of the code shown? import functools l=[1, 2, 3, 4, 5] m=functools.reduce(lambda x, y:x if x>y else y, l) print(m)

A. Error
B. Address of m
C. 1
D. 5
Answer» E.
413.

What is the output of the code shown? l=[1, 2, 3, 4, 5] m=map(lambda x:2**x, l) print(list(m))

A. [1, 4, 9, 16, 25 ]
B. [2, 4, 8, 16, 32 ]
C. [1, 0, 1, 0, 1]
D. Error
Answer» C. [1, 0, 1, 0, 1]
414.

What is the output of the following code? l=[1, -2, -3, 4, 5] def f1(x): return x

A. [False, False, False, False, False]
B. [False, True, True, False, False]
C. [True, False, False, True, True]
D. [True, True, True, True, True]
Answer» C. [True, False, False, True, True]
415.

What is the output of the code shown below? l=[-2, 4] m=map(lambda x:x*2, l) print(m)

A. [-4, 16]
B. Address of m
C. Error
D. -4 16
Answer» C. Error
416.

What is the output of the code shown? l=[1, -2, -3, 4, 5] def f1(x): return x

A. [1, 4, 5 ]
B. Error
C. [-2, -3]
D. [1, -2, -3]
Answer» E.
417.

What is the output of the code shown below? import functools l=[1,2,3,4] print(functools.reduce(lambda x,y:x*y,l))

A. Error
B. 10
C. 24
D. No output
Answer» D. No output
418.

What is the output of the code shown below? f=lambda x:bool(x%2) print(f(20), f(21))

A. False True
B. False False
C. True True
D. True False
Answer» B. False False
419.

The output of the code shown below is: odd=lambda x: bool(x%2) numbers=[n for n in range(10)] print(numbers) n=list() for i in numbers: if odd(i): continue else: break

A. [0, 2, 4, 6, 8, 10]
B. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
C. [1, 3, 5, 7, 9]
D. Error
Answer» C. [1, 3, 5, 7, 9]
420.

What is the output of the following piece of code? a = [1, 2, 3, 4, 5] b = lambda x: (b (x[1:]) + x[:1] if x else []) print(b (a))

A. 1 2 3 4 5.
B. [5,4,3,2,1].
C. [].
D. Error, lambda functions can’t be called recursively.
Answer» D. Error, lambda functions can’t be called recursively.
421.

What is the base case in the Merge Sort algorithm when it is solved recursively?

A. n=0
B. n=1
C. A list of length one
D. An empty list
Answer» D. An empty list
422.

What is the output of the piece of code given below? def check(n): if n < 2: return n % 2 == 0 return check(n - 2) print(check(11))

A. False
B. True
C. 1
D. An exception is thrown
Answer» B. True
423.

What is the output of the code shown below? l1=[1, 2, 3, (4)] l2=l1.copy() l2 l1

A. [1, 2, 3, (4)] [1, 2, 3, 4]
B. [1, 2, 3, 4] [1, 2, 3, (4)]
C. [1, 2, 3, 4] [1, 2, 3, 4]
D. [1, 2, 3, (4)] [1, 2, 3, (4)]
Answer» D. [1, 2, 3, (4)] [1, 2, 3, (4)]
424.

Fill in the blanks: In ____________________ copy, the modification done on one list affects the other list. In ____________________ copy, the modification done on one list does not affect the other list.

A. shallow, deep
B. memberwise, shallow
C. deep, shallow
D. deep, memberwise
Answer» B. memberwise, shallow
425.

What is the output of the code shown below? l1=[10, 20, 30, [40]] l2=copy.deepcopy(l1) l1[3][0]=90 l1 l2

A. [10, 20, 30, [40]] [10, 20, 30, 90]
B. Error
C. [10, 20, 30 [90]] [10, 20, 30, [40]]
D. [10, 20, 30, [40]] [10, 20, 30, [90]]
Answer» D. [10, 20, 30, [40]] [10, 20, 30, [90]]
426.

What is the output of the code shown below? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)

A. True
B. False
C. Error
D. Address of l1
Answer» C. Error
427.

What is the output of the codes shown below? l1=[10, 20, 30] l2=l1 id(l1)==id(l2) l2=l1.copy() id(l1)==id(l2)

A. False, False
B. False, True
C. True, True
D. True, False
Answer» E.
428.

The output of the code shown below and state the type of copy that is depicted: l1=[2, 4, 6, 8] l2=[1, 2, 3] l1=l2 l2

A. [2, 4, 6, 8], shallow copy
B. [2, 4, 6, 8], deep copy
C. [1, 2, 3], shallow copy
D. [1, 2, 3], deep copy
Answer» D. [1, 2, 3], deep copy
429.

n _______________ copy, the base address of the objects are copied. In _______________ copy, the base address of the objects are not copied.

A. deep. shallow
B. memberwise, shallow
C. shallow, deep
D. deep, memberwise
Answer» D. deep, memberwise
430.

What is the output of the code shown below? l=[2, 3, [4, 5]] l2=l.copy() l2[0]=88 l l2

A. [88, 2, 3, [4, 5]] [88, 2, 3, [4, 5]]
B. [2, 3, [4, 5]] [88, 2, 3, [4, 5]]
C. [88, 2, 3, [4, 5]] [2, 3, [4, 5]]
D. [2, 3, [4, 5]] [2, 3, [4, 5]]
Answer» C. [88, 2, 3, [4, 5]] [2, 3, [4, 5]]
431.

Which type of copy is shown in this code? l1=[[10, 20], [30, 40], [50, 60]] ls=list(l1) ls [[10, 20], [30, 40], [50, 60]]

A. Shallow copy
B. Deep copy
C. memberwise
D. All of the mentioned
Answer» B. Deep copy
432.

What is the output of the following piece of code? def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2) for i in range(0,4): print(a(i),end=" ")

A. 0 1 2 3
B. An exception is thrown
C. 0 1 1 2 3
D. 0 1 1 2
Answer» E.
433.

Which of these is not true about recursion?

A. Making the code look clean
B. A complex task can be broken into sub-problems
C. Recursive calls take up less memory
D. Sequence generation is easier than a nested iteration
Answer» D. Sequence generation is easier than a nested iteration
434.

What happens if the base condition isn’t defined in recursive programs?

A. Program gets into an infinite loop
B. Program runs once
C. Program runs n number of times where n is the argument given to the function
D. An exception is thrown
Answer» B. Program runs once
435.

What is the output of the following piece of code? def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))

A. 50
B. 100
C. 74
D. Infinite loop
Answer» C. 74
436.

Which of the following statements is false about recursion?

A. Every recursive function must have a base case
B. Infinite recursion can occur if the base case isn’t properly mentioned
C. A recursive function makes the code easier to understand
D. Every recursive function must have a return value
Answer» E.
437.

Observe the following piece of code? def a(n): if n == 0: return 0 else: return n*a(n - 1) def b(n, tot): if n == 0: return tot else: return b(n-2, tot-2)

A. Both a() and b() aren’t tail recursive
B. Both a() and b() are tail recursive
C. b() is tail recursive but a() isn’t
D. a() is tail recursive but b() isn’t
Answer» D. a() is tail recursive but b() isn’t
438.

What is tail recursion?

A. A recursive function that has two base cases
B. A function where the recursive functions leads to an infinite loop
C. A recursive function where the function doesn’t return anything and just prints the values
D. A function where the recursive call is the last thing executed by the function
Answer» E.
439.

What is the output of the following code? l=[] def convert(b): if(b==0): return l dig=b%2 l.append(dig) convert(b//2) convert(6) l.reverse() for i in l: print(i,end="")

A. 011
B. 110
C. 3
D. Infinite loop
Answer» C. 3
440.

What is the output of the following piece of code? def test(i,j): if(i==0): return j else: return test(i-1,i+j) print(test(4,7))

A. 13
B. 7
C. Infinite loop
D. 17
Answer» B. 7
441.

Fill in the line of code for calculating the factorial of a number. def fact(num): if num == 0: return 1 else: return _____________________

A. num*fact(num-1)
B. (num-1)*(num-2)
C. num*(num-1)
D. fact(num)*fact(num-1)
Answer» B. (num-1)*(num-2)
442.

Which of these is false about recursion?

A. Recursive function can be replaced by a non-recursive function
B. Recursive functions usually take more memory space than non-recursive function
C. Recursive functions run faster than non-recursive function
D. Recursion makes programs easier to understand
Answer» D. Recursion makes programs easier to understand
443.

Which is the most appropriate definition for recursion?

A. A function that calls itself
B. A function execution instance that calls another execution instance of the same function
C. A class method that calls another class method
D. An in-built method that is automatically called
Answer» C. A class method that calls another class method
444.

_____________ returns a dictionary of the module namespace. ________________ returns a dictionary of the current namespace.

A. locals() globals()
B. locals() locals()
C. globals() locals()
D. globals() globals()
Answer» D. globals() globals()
445.

What is the output of this code? def f(): x=4 x=1 f() x

A. Error
B. 4
C. Junk value
D. 1
Answer» E.
446.

What is the output of the code shown below? a=10 globals()['a']=25 print(a)

A. 10
B. 25
C. Junk value
D. Error
Answer» C. Junk value
447.

What happens if a local variable exists with the same name as the global variable you want to access?

A. Error
B. The local variable is shadowed
C. Undefined behavior
D. The global variable is shadowed
Answer» E.
448.

What is the output of the code shown below? e="butter" def f(a): print(a)+e f("bitter")

A. error
B. butter error
C. bitter error
D. bitterbutter
Answer» D. bitterbutter
449.

What is the output of the code shown below? x=1 def cg(): global x x=x+1 cg() x

A. 2
B. 1
C. 0
D. Error
Answer» B. 1
450.

Which of the following data structures is returned by the functions globals() and locals()?

A. list
B. set
C. dictionary
D. tuple
Answer» D. tuple