## Python Practice Test MCQ Certified Go from 0 to Expert hero Set 15

##### What will be the output of the following Python code?`s={2, 5, 6, 6, 7}s`

Options are :

• {2, 5, 7}
• {2, 5, 6, 7}
• {2, 5, 6, 6, 7}
• Error

Options are :

• True
• False

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

Options are :

• [x**3 for x in l]
• [x^3 for x in l]
• [x**3 in l]
• [x^3 in l]

Answer :[x**3 for x in l]

Options are :

• {1, 2, 3, 4}
• {1, 2, 4, 3}
• {4, 1, 2, 3}
• Error

Options are :

• pop
• remove
• uodate
• sum

Options are :

• True False
• False True
• True True
• False False

Options are :

• x | y
• x ^ y
• x & y
• x – y

Options are :

• True
• False
• No output
• Error

##### What will be the output of the following Python code snippet?`z=set('abc')z.add('san')z.update(set(['p', 'q']))z`

Options are :

• {'abc', 'p', 'q', 'san'}
• {'a', 'b', 'c', ['p', 'q'], 'san}
• {'a', 'c', 'c', 'p', 'q', 's', 'a', 'n'}
• {'a', 'b', 'c', 'p', 'q', 'san'}

Answer :{'a', 'b', 'c', 'p', 'q', 'san'}

##### What will be the output of the following Python code snippet?`s=set([1, 2, 3])s.union([4, 5])s|([4, 5])`

Options are :

• {1, 2, 3, 4, 5} {1, 2, 3, 4, 5}
• Error {1, 2, 3, 4, 5}
• {1, 2, 3, 4, 5} Error
• Error Error

Answer :{1, 2, 3, 4, 5} Error

Options are :

• pp qq rr
• pqr pqr
• ppqqrr
• pqrpqr

##### What will be the output of the following Python code snippet?`{a**2 for a in range(4)}`

Options are :

• {1, 4, 9, 16}
• {0, 1, 4, 9, 16}
• Error
• {0, 1, 4, 9}

##### What will be the output of the following Python function?`{x for x in 'abc'}{x*3 for x in 'abc'}`

Options are :

• {abc} aaa bbb ccc
• abc abc abc abc
• {'a', 'b', 'c'} {'aaa', 'bbb', 'ccc'}
• {'a', 'b', 'c'} abc abc abc

Answer : {'a', 'b', 'c'} {'aaa', 'bbb', 'ccc'}

Options are :

• True
• False

Options are :

• True False
• False False
• False True
• True True

##### What will be the output of the following Python code snippet?`l=[1, 2, 4, 5, 2, 'xy', 4]set(l)l`

Options are :

• {1, 2, 4, 5, 2, 'xy', 4} [1, 2, 4, 5, 2, 'xy', 4]
• {1, 2, 4, 5, 'xy'} [1, 2, 4, 5, 2, 'xy', 4]
• {1, 5, 'xy'} [1, 5, 'xy']
• {1, 2, 4, 5, 'xy'} [1, 2, 4, 5, 'xy']

Answer :{1, 2, 4, 5, 'xy'} [1, 2, 4, 5, 2, 'xy', 4]

##### What will be the output of the following Python code?`s1={3, 4}s2={1, 2}s3=set()i=0j=0for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1print(s3)`

Options are :

• {(3, 4), (1, 2)}
• Error
• {(4, 2), (3, 1), (4, 1), (5, 2)}
• {(3, 1), (4, 2)}

Answer :{(4, 2), (3, 1), (4, 1), (5, 2)}

Options are :

• remove
• pop
• dispose

##### The difference between the functions discard and remove is that:

Options are :

• Discard removes the last element of the set whereas remove removes the first element of the set
• 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
• Remove removes the last element of the set whereas discard removes the first element of the set
• 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 :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

##### What will be the output of the following Python code?`s1={1, 2, 3}s2={3, 4, 5, 6}s1.difference(s2)s2.difference(s1)`

Options are :

• {1, 2} {4, 5, 6}
• {1, 2} {1, 2}
• {4, 5, 6} {1, 2}
• {4, 5, 6} {4, 5, 6}

Answer :{1, 2} {4, 5, 6}

Options are :

• True False
• False True
• True True
• False False

##### 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:

Options are :

• s2.issubset(s1)
• s2.issuperset(s1)
• s1.issuperset(s2)
• s1.isset(s2)

##### What will be the output of the following Python code?`s1={1, 2, 3, 8}s2={3, 4, 5, 6}s1|s2s1.union(s2)`

Options are :

• {3} {1, 2, 3, 4, 5, 6, 8}
• {1, 2, 4, 5, 6, 8} {1, 2, 4, 5, 6, 8}
• {3} {3}
• {1, 2, 3, 4, 5, 6, 8} {1, 2, 3, 4, 5, 6, 8}

Answer :{1, 2, 3, 4, 5, 6, 8} {1, 2, 3, 4, 5, 6, 8}

##### What will be the output of the following Python code?`a=set('abc')b=set('def')b.intersection_update(a)ab`

Options are :

• set() ('e', 'd', 'f'}
• {} {}
• {'b', 'c', 'a'} set()
• set() set()

Options are :

• True
• Error
• No outout
• False

##### What will be the output of the following Python code?`x=set('abcde')y=set('xyzbd')x.difference_update(y)xy`

Options are :

• {'a', 'b', 'c', 'd', 'e'} {'x', 'y', 'z'}
• {'a', 'c', 'e'} {'x', 'y', 'z', 'b', 'd'}
• {'b', 'd'} {'b', 'd'}
• {'a', 'c', 'e'} {'x', 'y', 'z'}

Answer :{'a', 'c', 'e'} {'x', 'y', 'z', 'b', 'd'}

##### Which of the following statements create a dictionary?

Options are :

• d = {}
• d = {"john":40, "peter":45}
• d = {40:"john", 45:"peter"}
• All of the mentioned

##### What will be the output of the following Python code snippet?`d = {"john":40, "peter":45}`

Options are :

• "john", 40, 45, and "peter"
• "john" and "peter"
• 40 and 45
• d = (40:"john", 45:"peter")

Options are :

• True
• False
• None
• Error

Options are :

• True
• False
• None
• Error