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.

601.

What is the output of the snippet of code shown below? x=set('abcde') y=set('xyzbd') x.difference_update(y) x y

A. {‘a’, ‘b’, ‘c’, ‘d’, ‘e’} {‘x’, ‘y’, ‘z’}
B. {‘a’, ‘c’, ‘e’} {‘x’, ‘y’, ‘z’, ‘b’, ‘d’}
C. {‘b’, ‘d’} {‘b’, ‘d’}
D. {‘a’, ‘c’, ‘e’} {‘x’, ‘y’, ‘z’}
Answer» C. {‘b’, ‘d’} {‘b’, ‘d’}
602.

What is the output of the line of code shown below, if s1= {1, 2, 3}? s1.issubset(s1)

A. True
B. Error
C. No output
D. False
Answer» B. Error
603.

What is the output of the code shown below? a=set('abc') b=set('def') b.intersection_update(a) a b

A. set() (‘e’, ‘d’, ‘f’}
B. {} {}
C. {‘b’, ‘c’, ‘a’} set()
D. set() set()
Answer» D. set() set()
604.

What is the output of this code? s1={1, 2, 3, 8} s2={3, 4, 5, 6} s1|s2 s1.union(s2)

A. {3} {1, 2, 3, 4, 5, 6, 8}
B. {1, 2, 4, 5, 6, 8} {1, 2, 4, 5, 6, 8}
C. {3} {3}
D. {1, 2, 3, 4, 5, 6, 8} {1, 2, 3, 4, 5, 6, 8}
Answer» E.
605.

If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:

A. s2.issubset(s1)
B. s2.issuperset(s1)
C. s1.issuperset(s2)
D. s1.isset(s2)
Answer» C. s1.issuperset(s2)
606.

The difference between the functions discard and remove is that:

A. Discard removes the last element of the set whereas remove removes the first element of the set
B. Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element
C. Remove removes the last element of the set whereas discard removes the first element of the set
D. Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element
Answer» E.
607.

The ____________ function removes the first element of a set and the last element of a list

A. remove
B. pop
C. discard
D. dispose
Answer» C. discard
608.

What is the output of the code shown below? s1={3, 4} s2={1, 2} s3=set() i=0 j=0 for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1 print(s3)

A. {(3, 4), (1, 2)}
B. Error
C. {(4, 2), (3, 1), (4, 1), (5, 2)}
D. {(3, 1), (4, 2)}
Answer» D. {(3, 1), (4, 2)}
609.

What is the output of the code shown below? l=[1, 2, 4, 5, 2, 'xy', 4] set(l) l

A. {1, 2, 4, 5, 2, ‘xy’, 4} [1, 2, 4, 5, 2, ‘xy’, 4]
B. {1, 2, 4, 5, ‘xy’} [1, 2, 4, 5, 2, ‘xy’, 4]
C. {1, 5, ‘xy’} [1, 5, ‘xy’
D. {1, 2, 4, 5, ‘xy’} [1, 2, 4, 5, ‘xy’]
Answer» C. {1, 5, ‘xy’} [1, 5, ‘xy’
610.

The output of the code shown below is: a=[1, 4, 3, 5, 2] b=[3, 1, 5, 2, 4] a==b set(a)==set(b)

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

What is the output of the following code? {a**2 for a in range(4)}

A. {1, 4, 9, 16}
B. {0, 1, 4, 9, 16}
C. Error
D. {0, 1, 4, 9}
Answer» E.
612.

What is the output of the code shown below? for x in set('pqr'): print(x*2)

A. pp qq rr
B. pqr pqr
C. ppqqrr
D. pqrpqr
Answer» B. pqr pqr
613.

What is the output of the code shown below? s=set([1, 2, 3]) s.union([4, 5]) s|([4, 5])

A. {1, 2, 3, 4, 5} {1, 2, 3, 4, 5}
B. Error {1, 2, 3, 4, 5}
C. {1, 2, 3, 4, 5} Error
D. Error Error
Answer» D. Error Error
614.

What is the output of the code shown below? z=set('abc') z.add('san') z.update(set(['p', 'q'])) z

A. {‘abc’, ‘p’, ‘q’, ‘san’}
B. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
C. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
D. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
Answer» E.
615.

What is the output of the snippet of code shown below? z=set('abc$de') 'a' in z

A. True
B. False
C. No output
D. Error
Answer» B. False
616.

Which of the following functions will return the symmetric difference between two sets, x and y?

A. x | y
B. x ^ y
C. x & y
D. x – y
Answer» D. x – y
617.

What is the output of the code shown below? s={1, 2, 3} s.update(4) s

A. {1, 2, 3, 4}
B. {1, 2, 4, 3}
C. {4, 1, 2, 3}
D. Error
Answer» E.
618.

Write a list comprehension for number and its cube for: l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

A. [x**3 for x in l]
B. [x^3 for x in l]
C. [x**3 in l]
D. [x^3 in l]
Answer» B. [x^3 for x in l]
619.

What is the output of the code shown below? s={2, 5, 6, 6, 7} s

A. {2, 5, 7}
B. {2, 5, 6, 7}
C. {2, 5, 6, 6, 7}
D. Error
Answer» C. {2, 5, 6, 6, 7}
620.

Which of the following lines of code will result in an error?

A. s={abs}
B. s={4, ‘abc’, (1,2)}
C. s={2, 2.2, 3, ‘xyz’}
D. s={san}
Answer» E.
621.

Set makes use of __________ Dictionary makes use of ____________

A. keys, keys
B. key values, keys
C. keys, key values
D. key values, key values
Answer» D. key values, key values
622.

What is the output of the code shown? s=set() type(s)

A. <’set’>
B. <class ‘set’>
C. set
D. class set
Answer» C. set
623.

Is the following piece of code valid? a={1,2,3} b={1,2,3,4} c=a.issuperset(b) print(c)

A. False
B. True
C. Syntax error for issuperset() method
D. Error, no method called issuperset() exists
Answer» B. True
624.

What is the output of the following piece of code? a={1,2,3} b={1,2,3} c=a.issubset(b) print(c)

A. True
B. Error, no method called issubset() exists
C. Syntax error for issubset() method
D. False
Answer» B. Error, no method called issubset() exists
625.

What is the output of the following piece of code? >>> a={5,6,7,8} >>> b={7,8,9,10} >>> len(a+b)

A. 8
B. Error, unsupported operand ‘+’ for sets
C. 6
D. Nothing is displayed
Answer» C. 6
626.

What is the output of the following code? >>> a={1,2,3} >>> {x*2 for x in a|{4,5}}

A. {2,4,6}
B. Error, set comprehensions aren’t allowed
C. {8, 2, 10, 4, 6}
D. {8,10}
Answer» D. {8,10}
627.

What is the output of the following piece of code? >>> a={5,6,7} >>> sum(a,5)

A. 5
B. 23
C. 18
D. Invalid syntax for sum method, too many arguments
Answer» C. 18
628.

What is the output of the following code? >>> a={1,2,3} >>> b=frozenset([3,4,5]) >>> a-b

A. {1,2}
B. Error as difference between a set and frozenset can’t be found out
C. Error as unsupported operand type for set data type
D. frozenset({1,2})
Answer» B. Error as difference between a set and frozenset can’t be found out
629.

What is the output of the following code? >>> a={1,2,3} >>> b=a.add(4) >>> b

A. None
B. {1,2,3,4}
C. {1,2,3}
D. Nothing is printed
Answer» E.
630.

What is the output of the following piece of code? >>> a={1,2,3} >>> b=a.copy() >>> b.add(4) >>> a

A. {1,2,3}
B. Error, invalid syntax for add
C. {1,2,3,4}
D. Error, copying of sets isn’t allowed
Answer» B. Error, invalid syntax for add
631.

What is the output for the following piece of code? >>> a={1,2,3} >>> b=a >>> b.remove(3) >>> a

A. {1,2,3}
B. Error, copying of sets isn’t allowed
C. {1,2}
D. Error, invalid syntax for remove
Answer» D. Error, invalid syntax for remove
632.

What is the output of the following piece of code when executed in the python shell? >>> a={1,2,3} >>> a.intersection_update({2,3,4,5}) >>> a

A. {2,3}
B. Error, duplicate item present in list
C. Error, no method called intersection_update for set data type
D. {1,4,5}
Answer» B. Error, duplicate item present in list
633.

What is the output of the following piece of code? >>> a={3,4,5} >>> a.update([1,2,3]) >>> a

A. Error, no method called update for set data type
B. {1, 2, 3, 4, 5}
C. Error, list can’t be added to set
D. Error, duplicate item present in list
Answer» C. Error, list can’t be added to set
634.

Is the following piece of code valid? >>> a=frozenset([5,6,7]) >>> a >>> a.add(5)

A. Yes, now a is {5,5,6,7}
B. No, frozen set is immutable
C. No, invalid syntax for add method
D. Yes, now a is {5,6,7}
Answer» C. No, invalid syntax for add method
635.

What is the syntax of the following piece of code? >>> a=frozenset(set([5,6,7])) >>> a

A. {5,6,7}
B. frozenset({5,6,7})
C. Error, not possible to convert set into frozenset
D. Syntax error
Answer» C. Error, not possible to convert set into frozenset
636.

Which of these about a frozenset is not true?

A. Mutable data type
B. Allows duplicate values
C. Allows duplicate values
D. Immutable data type
Answer» B. Allows duplicate values
637.

Is the following piece of code valid? a={3,4,{7,5}} print(a[2][0])

A. Yes, 7 is printed
B. Error, elements of a set can’t be printed
C. Error, subsets aren’t allowed
D. Yes, {7,5} is printed
Answer» D. Yes, {7,5} is printed
638.

What is the output of the following piece of code? >>> a={3,4,5} >>> b={5,6,7} >>> a|b

A. Invalid operation
B. {3, 4, 5, 6, 7}
C. {5}
D. {3,4,6,7}
Answer» E.
639.

What is the output of the following code? >>> s={5,6} >>> s*3

A. Error as unsupported operand type for set data type
B. {5,6,5,6,5,6}
C. {5,6}
D. Error as multiplication creates duplicate elements which isn’t allowed
Answer» B. {5,6,5,6,5,6}
640.

What is the output of the following piece of code? >>> a={5,6,7,8} >>> b={7,8,10,11} >>> a^b

A. {5,6,7,8,10,11}
B. {7,8}
C. Error as unsupported operand type of set data type
D. {5,6,10,11}
Answer» E.
641.

What is the output of the following code? >>> a={4,5,6} >>> b={2,8,6} >>> a-b

A. {4,5}
B. {6}
C. Error as unsupported operand type for set data type
D. Error as the duplicate item 6 is present in both sets
Answer» B. {6}
642.

What is the output of the following code? >>> a={4,5,6} >>> b={2,8,6} >>> a+b

A. {4,5,6,2,8}
B. {4,5,6,2,8,6}
C. Error as unsupported operand type for sets
D. Error as the duplicate item 6 is present in both sets
Answer» D. Error as the duplicate item 6 is present in both sets
643.

If a={5,6,7}, what happens when a.add(5) is executed?

A. a={5,5,6,7}
B. a={5,6,7}
C. Error as there is no add function for set data type
D. Error as 5 already exists in the set
Answer» C. Error as there is no add function for set data type
644.

If a={5,6,7,8}, which of the following statements is false?

A. print(len(a))
B. print(min(a))
C. a.remove(5)
D. a[2]=45
Answer» E.
645.

What is the output of the following piece of code when executed in the python shell? >>> a={5,4} >>> b={1,2,4,5} >>> a

A. {1,2}
B. True
C. False
D. Invalid operation
Answer» C. False
646.

Which of the following statements is used to create an empty set?

A. { }
B. set()
C. [ ].
D. ( )
Answer» C. [ ].
647.

What is the output of the following piece of code? a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a): print(i,end=" ")

A. 5 5 6
B. 5 6 7
C. 5 5 6 7 7 7
D. 5 6 7 7 7
Answer» D. 5 6 7 7 7
648.

What is the output of the following code? nums = set([1,1,2,3,3,3,4,4]) print(len(nums)

A. 7
B. Error, invalid syntax for formation of set
C. 4
D. 8
Answer» D. 8
649.

Which of the following is not the correct syntax for creating a set?

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

Which of these about a set is not true?

A. Mutable data type
B. Allows duplicate values
C. Data type with unordered values
D. Immutable data type
Answer» E.