Sets Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
Which operator represents symmetric difference?
  • A -
  • B &
  • C |
  • D ^
Answer: Option D
Explanation: The caret (^) operator performs symmetric difference between two sets.
Q12
What is the result of len({1, 1, 2, 2, 3})?
  • A 5
  • B 3
  • C 2
  • D Error
Answer: Option B
Explanation: Sets remove duplicates, so {1, 1, 2, 2, 3} becomes {1, 2, 3} with length 3.
Q13
Which method removes a specific element from a set and raises error if not found?
  • A discard()
  • B remove()
  • C pop()
  • D delete()
Answer: Option B
Explanation: remove() raises KeyError if element is not found, while discard() does not raise an error.
Q14
What is the output of: {1, 2, 3} | {3, 4, 5}?
  • A {1, 2, 3, 4, 5}
  • B {3}
  • C {1, 2, 4, 5}
  • D {1, 2, 3}
Answer: Option A
Explanation: The | operator performs union operation, combining all unique elements from both sets.
Q15
Which method checks if a set is a subset of another?
  • A subset()
  • B contains()
  • C issubset()
  • D partof()
Answer: Option C
Explanation: issubset() checks if all elements of one set are present in another set.
Q16
What is the result of: {1, 2}.issuperset({1})?
  • A True
  • B False
  • C Error
  • D None
Answer: Option A
Explanation: issuperset() returns True if the set contains all elements of the specified set.
Q17
Which method removes all elements from a set?
  • A delete()
  • B remove_all()
  • C clear()
  • D empty()
Answer: Option C
Explanation: clear() removes all elements from the set, making it empty.
Q18
What is the output of: {1, 2} - {2, 3}?
  • A {1}
  • B {2}
  • C {1, 3}
  • D {3}
Answer: Option A
Explanation: The - operator returns elements that are in the first set but not in the second set.
Q19
Which of these data types can be elements of a set?
  • A Lists
  • B Dictionaries
  • C Other sets
  • D Tuples
Answer: Option D
Explanation: Sets can contain only hashable (immutable) types. Lists are mutable and cannot be set elements.
Q20
What is the result of: {1, 2} ^ {2, 3}?
  • A {1, 3}
  • B {2}
  • C {1, 2, 3}
  • D {}
Answer: Option A
Explanation: Symmetric difference returns elements that are in either set but not in both.
Questions and Answers for Competitive Exams Various Entrance Test