Sets Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
Which operator represents symmetric difference?
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})?
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?
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}?
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?
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})?
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?
Answer: Option C
Explanation: clear() removes all elements from the set, making it empty.
Q18
What is the output of: {1, 2} - {2, 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?
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}?
Answer: Option A
Explanation: Symmetric difference returns elements that are in either set but not in both.