Python/Python Mcq Set 10 Sample Test,Sample questions

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

1. Discard removes the last element of the set whereas remove removes the first element of the set

2.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

3. Remove removes the last element of the set whereas discard removes the first element of the set

4.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


Question:
 The following Python code results in an error.

s={2, 3, 4, [5, 6]}

1. True

2. False

3.None of the above

4.all of the mentioned


Question:
 What will be the output of the following Python code snippet?

{a**2 for a in range(4)}

1.{1, 4, 9, 16}

2. {0, 1, 4, 9, 16}

3.Error

4.{0, 1, 4, 9}


Question:
 What will be the output of the following Python code?

>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a

1. {2,3}

2. Error, duplicate item present in list

3.Error, no method called intersection_update for set data type

4.{1,4,5}


Question:
 What will be the output of the following Python code?

>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a

1. Error, no method called update for set data type

2. {1, 2, 3, 4, 5}

3.Error, list can’t be added to set

4.Error, duplicate item present in list


Question:
 What will be the output of the following Python code?

>>> a={3,4,5}
>>> b={5,6,7}
>>> a|b

1.Invalid operation

2.{3, 4, 5, 6, 7}

3.{5}

4. {3,4,6,7}


Question:
 What will be the output of the following Python code?

>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b

1. {4,5}

2. {6}

3. Error as unsupported operand type for set data type

4. Error as the duplicate item 6 is present in both sets


Question:
 What will be the output of the following Python code?

>>> a={5,6,7}
>>> sum(a,5)

1.5

2.23

3.18

4.Invalid syntax for sum method, too many arguments


Question:
 What will be the output of the following Python code?

a={1,2,3}
b={1,2,3}
c=a.issubset(b)
print(c)

1.True

2. Error, no method called issubset() exists

3.Syntax error for issubset() method

4. False


Question:
 What will be the output of the following Python code?

s={2, 5, 6, 6, 7}
s

1.{2, 5, 7}

2. {2, 5, 6, 7}

3. {2, 5, 6, 6, 7}

4.error


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

1. x | y

2.x ^ y

3.x & y

4. x – y


Question:
 Which of the following statements create a dictionary?

1.d = {}

2.d = {“john”:40, “peter”:45}

3.d = {“john”:40, “peter”:45}

4.all of the mentioned


Question:
 Which of these about a frozenset is not true?

1.Mutable data type

2.Allows duplicate values

3. Data type with unordered values

4.Immutable data type


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

1. print(len(a))

2. print(min(a))

3.a.remove(5)

4. a[2]=45


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

1. a={5,5,6,7}

2.a={5,6,7}

3.Error as there is no add function for set data type

4.Error as 5 already exists in the set


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

1. s2.issubset(s1)

2. s2.issuperset(s1)

3.s1.issuperset(s2)

4.s1.isset(s2)


Question:
Is the following Python code valid?

a={1,2,3}
b={1,2,3,4}
c=a.issuperset(b)
print(c)

1. False

2.True

3.Syntax error for issuperset() method

4.Error, no method called issuperset() exists


Question:
Is the following Python code valid?

a={3,4,{7,5}}
print(a[2][0])

1.Yes, 7 is printed

2.Error, elements of a set can’t be printed

3.Error, subsets aren’t allowed

4.Yes, {7,5} is printed


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

1.Yes, now a is {5,5,6,7}

2.No, frozen set is immutable

3. No, invalid syntax for add method

4.Yes, now a is {5,6,7}


Question:
Set makes use of ____
Dictionary makes use of ______

1. keys, keys

2.key values, keys

3.keys, key values

4.key values, key values


Question:
Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

1.d.delete(“john”:40)

2.d.delete(“john”)

3. del d[“john”]

4.del d(“john”:40)


Question:
Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?

1.d.size()

2.len(d)

3.size(d)

4. d.len()


Question:
The output of the following code is: class<’set’>.

type({})

1. True

2. False

3.Both a & b

4.None of these


Question:
The ______ function removes the first element of a set and the last element of a list.

1.remove

2. pop

3.discard

4.dispose


Question:
What is the syntax of the following Python code?

>>> a=frozenset(set([5,6,7]))
>>> a

1. {5,6,7}

2.frozenset({5,6,7})

3.Error, not possible to convert set into frozenset

4.Syntax error


Question:
What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}
d["john"]

1.40

2.45

3.“john”

4.“peter”


Question:
What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}
print(list(d.keys()))

1. [“john”, “peter”]

2.[“john”:40, “peter”:45]

3.(“john”, “peter”)

4. (“john”:40, “peter”:45)


Question:
What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

1. “john”, 40, 45, and “peter”

2.“john” and “peter”

3.40 and 45

4.d = (40:”john”, 45:”peter”)


Question:
What will be the output of the following Python code snippet?

d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2

1.True

2.False

3.Error

4.None of these


Question:
What will be the output of the following Python code snippet?

d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2

1.True

2.False

3. None

4.error


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

1. {‘abc’, ‘p’, ‘q’, ‘san’}

2. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}

3. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}

4. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}


Question:
What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=a
>>> b.remove(3)
>>> a

1. {1,2,3}

2.Error, copying of sets isn’t allowed

3. {1,2}

4.Error, invalid syntax for remove


Question:
What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=a.add(4)
>>> b

1. 0

2.{1,2,3,4}

3.{1,2,3}

4. Nothing is printed


Question:
What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=a.copy()
>>> b.add(4)
>>> a

1. {1,2,3}

2.Error, invalid syntax for add

3. {1,2,3,4}

4.Error, copying of sets isn’t allowed


Question:
What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=frozenset([3,4,5])
>>> a-b

1. {1,2}

2.Error as difference between a set and frozenset can’t be found out

3. Error as unsupported operand type for set data type

4. frozenset({1,2})


Question:
What will be the output of the following Python code?

>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}

1. {2,4,6}

2.Error, set comprehensions aren’t allowed

3. {8, 2, 10, 4, 6}

4.{8,10}


Question:
What will be the output of the following Python code?

>>> a={4,5,6}
>>> b={2,8,6}
>>> a+b

1.{4,5,6,2,8}

2.{4,5,6,2,8,6}

3.Error as unsupported operand type for sets

4.Error as the duplicate item 6 is present in both sets


Question:
What will be the output of the following Python code?

>>> a={5,4}
>>> b={1,2,4,5}
>>> a<b

1.{1,2}

2.True

3.False

4.Invalid operation


Question:
What will be the output of the following Python code?

>>> a={5,6,7,8}
>>> b={7,8,10,11}
>>> a^b

1. {5,6,7,8,10,11}

2. {7,8}

3.Error as unsupported operand type of set data type

4. {5,6,10,11}


Question:
What will be the output of the following Python code?

>>> a={5,6,7,8}
>>> b={7,8,9,10}
>>> len(a+b)

1.8

2. Error, unsupported operand ‘+’ for sets

3.6

4. Nothing is displayed


Question:
What will be the output of the following Python code?

>>> s={5,6}
>>> s*3

1.Error as unsupported operand type for set data type

2.{5,6,5,6,5,6}

3.{5,6}

4.Error as multiplication creates duplicate elements which isn’t allowed


Question:
What will be the output of the following Python 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=" ")

1. 5 5 6

2. 5 6 7

3. 5 5 6 7 7 7

4.5 6 7 7 7


Question:
What will be the output of the following Python code?

s=set()
type(s)

1. <’set’>

2. <class ‘set’>

3.set

4. class set


Question:
What will be the output of the following Python code?

s={1, 2, 3}
s.update(4)
s

1.{1, 2, 3, 4}

2.{1, 2, 4, 3}

3.{4, 1, 2, 3}

4.error


Question:
What will be the output of the following Python code?
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))

1.7

2.Error, invalid syntax for formation of set

3.4

4.8


Question:
Which of the following functions cannot be used on heterogeneous sets?

1. pop

2.remove

3.update

4.sum


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

1.set([[1,2],[3,4]])

2. set([1,2,2,3,4])

3.set((1,2,3,4))

4. {1,2,3,4}


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

1.s={abs}

2.s={4, ‘abc’, (1,2)}

3.s={2, 2.2, 3, ‘xyz’}

4.s={san}


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

1.{ }

2.set()

3.[ ]

4. ( )


Question:
Write a list comprehension for number and its cube for:

l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

1.[x**3 for x in l]

2.[x^3 for x in l]

3. [x**3 in l]

4. [x^3 in l]


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!