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.

651.

What is the output of the following piece of code? >>> a=[(2,4),(1,2),(3,9)] >>> a.sort() >>> a

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
Answer» E.
652.

. Is the following piece of code valid? >>> a=(1,2,3) >>> b=a.update(4,)

A. Yes, a=(1,2,3,4) and b=(1,2,3,4)
B. Yes, a=(1,2,3) and b=(1,2,3,4)
C. No because tuples are immutable
D. No because wrong syntax for update() method
Answer» D. No because wrong syntax for update() method
653.

What is the output of the following piece of code? >>> a=(2,3,1,5) >>> a.sort() >>> a

A. (1,2,3,5)
B. (2,3,1,5)
C. None
D. Error, tuple has no attribute sort
Answer» E.
654.

Is the following piece of code valid? >>> a=2,3,4,5 >>> a

A. Yes, 2 is printed
B. Yes, [2,3,4,5] is printed
C. No, too many values to unpack
D. Yes, (2,3,4,5) is printed
Answer» E.
655.

What is the output of the following code? >>> import collections >>> a=collections.namedtuple('a',['i','j']) >>> obj=a(i=4,j=7) >>> obj

A. a(i=4, j=7)
B. obj(i=4, j=7)
C. (4,7)
D. An exception is thrown
Answer» B. obj(i=4, j=7)
656.

What is the output of the following code? >>> a,b=6,7 >>> a,b=b,a >>> a,b

A. (6,7)
B. Invalid syntax
C. (7,6)
D. Nothing is printed
Answer» D. Nothing is printed
657.

. What is the output of the following piece of code when executed in Python shell? >>> a=(1,2) >>> b=(3,4) >>> c=a+b >>> c

A. (4,6)
B. (1,2,3,4)
C. Error as tuples are immutable
D. None
Answer» C. Error as tuples are immutable
658.

Is the following line of code valid? >>> a,b=1,2,3

A. Yes, this is an example of tuple unpacking. a=1 and b=2
B. Yes, this is an example of tuple unpacking. a=(1,2) and b=3
C. No, too many values to unpack
D. Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
Answer» D. Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
659.

What is the output of the following piece of code? a = ('check',) n = 2 for i in range(int(n)): a = (a,) print(a)

A. Error, tuples are immutable
B. ((‘check’,),) (((‘check’,),),).
C. ((‘check’,)’check’,)
D. ((‘check’,)’check’,) (((‘check’,)’check’,)’check’,)
Answer» C. ((‘check’,)’check’,)
660.

Is the following piece of code valid? >>> a,b,c=1,2,3 >>> a,b,c

A. Yes, [1,2,3] is printed
B. No, invalid syntax
C. Yes, (1,2,3) is printed
D. 1 is printed
Answer» D. 1 is printed
661.

Is the following piece of code valid? >>> a=(1,2,3) >>> b=('A','B','C') >>> c=zip(a,b)

A. Yes, c will be ((1,2,3),(‘A’,’B’,’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
Answer» B. Yes, c will be ((1,2,3),(‘A’,’B’,’C’))
662.

What is the output of the following piece of code? >>> a=(0,1,2,3,4) >>> b=slice(0,2) >>> a[b]

A. Invalid syntax for slicing
B. [0,2].
C. (0,1)
D. (0,2)
Answer» D. (0,2)
663.

What type of data is: a=[(1,1),(2,4),(3,9)]?

A. Array of tuples
B. List of tuples
C. Tuples of lists
D. Invalid type
Answer» C. Tuples of lists
664.

Is the following piece of code valid? >>> a=(1,2,3,4) >>> del a

A. No because tuple is immutable
B. Yes, first element in the tuple is deleted
C. Yes, the entire tuple is deleted
D. No, invalid syntax for del method
Answer» D. No, invalid syntax for del method
665.

What is the output of the following code? >>> a=(2,3,4) >>> sum(a,3)

A. What is the output of the following code? >>> a=(2,3,4) >>> sum(a,3)
B. The method sum() doesn’t exist for tuples
C. 12
D. 9
Answer» D. 9
666.

What is the output of the following code? >>> a=(1,2,3,4) >>> del(a[2])

A. Now, a=(1,2,4)
B. Now, a=(1,3,4)
C. Now a=(3,4)
D. Error as tuple is immutable
Answer» E.
667.

What is the output of the following piece of code when executed in Python shell? >>> a=("Check")*3 >>> a

A. (‘Check’,’Check’,’Check’)
B. * Operator not valid for tuples
C. (‘CheckCheckCheck’)
D. Syntax error
Answer» D. Syntax error
668.

What is the output of the following code? >>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a

A. False
B. True
C. Error, < operator is not valid for tuples
D. Error, < operator is valid for tuples but not if there are sub-tuples
Answer» B. True
669.

If a=(1,2,3,4), a[1:-1] is

A. Error, tuple slicing doesn’t exist
B. [2,3].
C. (2,3,4)
D. (2,3)
Answer» E.
670.

What is the data type of (1)?

A. Tuple
B. Integer
C. List
D. Both tuple and integer
Answer» C. List
671.

What will be the output? numberGames = {} numberGames[(1,2,4)] = 8 numberGames[(4,2,1)] = 10 numberGames[(1,2)] = 12 sum = 0 for k in numberGames: sum += numberGames[k] print len(numberGames) + sum

A. 30
B. 24
C. 33
D. 12
Answer» D. 12
672.

What will be the output? >>>t1 = (1, 2, 4, 3) >>>t2 = (1, 2, 3, 4) >>>t1 < t2

A. True
B. False
C. Error
D. None
Answer» C. Error
673.

What will be the output? >>>t = (1, 2) >>>2 * t

A. (1, 2, 1, 2)
B. [1, 2, 1, 2].
C. (1, 1, 2, 2)
D. (1, 1, 2, 2)
Answer» B. [1, 2, 1, 2].
674.

What will be the output? d = {"john":40, "peter":45} d["john"]

A. 40
B. 45
C. john”
D. peter”
Answer» B. 45
675.

What will be the output? >>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)]

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

What will be the output? >>>t=(1,2,4,3) >>>t[1:-1]

A. (1, 2)
B. (1, 2, 4)
C. (2, 4)
D. (2, 4, 3)
Answer» D. (2, 4, 3)
677.

What will be the output? >>>t=(1,2,4,3) >>>t[1:3]

A. (1, 2)
B. (1, 2)
C. (2, 4)
D. (2, 4, 3)
Answer» D. (2, 4, 3)
678.

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

A. print(t[3])
B. t[3] = 45
C. print(max(t))
D. print(len(t))
Answer» C. print(max(t))
679.

Which of the following is a Python tuple?

A. [1, 2, 3].
B. (1, 2, 3)
C. {1, 2, 3}
D. {}
Answer» C. {1, 2, 3}
680.

. What will be the output? def addItem(listParam): listParam += [1] mylist = [1, 2, 3, 4] addItem(mylist) print(len(mylist))

A. 1
B. 4
C. 5
D. 8
Answer» D. 8
681.

What will be the output? list1 = [1, 2, 3, 4] list2 = [5, 6, 7, 8] print(len(list1 + list2))

A. 2
B. 4
C. 5
D. 8
Answer» E.
682.

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
Answer» E.
683.

What will be the output? numbers = [1, 2, 3, 4] numbers.append([5,6,7,8]) print(len(numbers))

A. 4
B. 5
C. 8
D. 12
Answer» C. 8
684.

What will be the output? names1 = ['Amir', 'Bala', 'Charlie'] names2 = [name.lower() for name in names1] print(names2[2][0])

A. None
B. a
C. b
D. c
Answer» E.
685.

What will be the output? names1 = ['Amir', 'Bala', 'Chales'] if 'amir' in names1: print(1) else: print(2)

A. None
B. 1
C. 2
D. Error
Answer» D. Error
686.

What will be the output? def f(i, values = []): values.append(i) return values f(1) f(2) v = f(3) print(v)

A. [1] [2] [3].
B. [1] [1, 2] [1, 2, 3].
C. [1, 2, 3].
D. 1 2 3
Answer» D. 1 2 3
687.

What is the output when following code is executed ? def f(values): values[0] = 44 v = [1, 2, 3] f(v) print(v)

A. [1, 44].
B. [1, 2, 3, 44].
C. [44, 2, 3].
D. [1, 2, 3].
Answer» D. [1, 2, 3].
688.

What is the output when following code is executed ? >>>list1 = [1, 3] >>>list2 = list1 >>>list1[0] = 4 >>>print(list2)

A. [1, 3].
B. [4, 3].
C. [1, 4].
D. [1, 3, 4].
Answer» C. [1, 4].
689.

What is the output when following code is executed ? >>>list("a#b#c#d".split('#'))

A. [‘a’, ‘b’, ‘c’, ‘d’].
B. [‘a b c d’].
C. [‘a#b#c#d’].
D. [‘abcd’].
Answer» B. [‘a b c d’].
690.

What is the output when the following code is executed ? >>>"Welcome to Python".split()

A. [“Welcome”, “to”, “Python”].
B. (“Welcome”, “to”, “Python”)
C. {“Welcome”, “to”, “Python”}
D. “Welcome”, “to”, “Python”
Answer» B. (“Welcome”, “to”, “Python”)
691.

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].
Answer» B. [1, 3, 3, 4, 5, 5, 20, 25].
692.

Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1) ?

A. [3, 4, 5, 20, 5, 25, 1, 3].
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].
Answer» D. [1, 3, 4, 5, 20, 5, 25].
693.

Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34, 5]) ?

A. [3, 4, 5, 20, 5, 25, 1, 3, 34, 5].
B. [1, 3, 3, 4, 5, 5, 20, 25, 34, 5].
C. [25, 20, 5, 5, 4, 3, 3, 1, 34, 5].
D. [1, 3, 4, 5, 20, 5, 25, 3, 34, 5].
Answer» B. [1, 3, 3, 4, 5, 5, 20, 25, 34, 5].
694.

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse() ?

A. [3, 4, 5, 20, 5, 25, 1, 3].
B. [1, 3, 3, 4, 5, 5, 20, 25].
C. [25, 20, 5, 5, 4, 3, 3, 1].
D. [3, 1, 25, 5, 20, 5, 4, 3].
Answer» E.
695.

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5) ?

A. 0
B. 4
C. 1
D. 2
Answer» E.
696.

Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5) ?

A. 0
B. 1
C. 4
D. 2
Answer» E.
697.

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”)
Answer» B. list1.remove(hello)
698.

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)
Answer» B. list1.insert(2, 5)
699.

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)
Answer» C. list1.addLast(5)
700.

What is the output when following code is executed ? >>>list1 = [11, 2, 23] >>>list2 = [11, 2, 2] >>>list1 < list2 is

A. True
B. False
C. Error
D. None
Answer» C. Error