Sets Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
Which of the following creates an empty set in Python?
Answer: Option B
Explanation: Curly braces {} without values create an empty dictionary, not a set. To create an empty set, you must use the set() constructor.
Q2
What is the output of: set([1, 2, 3, 2, 1])?
Answer: Option B
Explanation: Sets automatically remove duplicate elements, so [1, 2, 3, 2, 1] becomes {1, 2, 3}.
Q3
Which method adds an element to a set?
Answer: Option C
Explanation: add() method adds a single element to a set, while update() adds multiple elements from an iterable.
Q4
What does the union() method do for sets?
Answer: Option B
Explanation: Union returns a new set containing all elements from both sets without duplicates.
Q5
Which operator is used for set difference in Python?
Answer: Option A
Explanation: The minus (-) operator returns elements present in the first set but not in the second set.
Q6
What is the result of: {1, 2, 3} & {2, 3, 4}?
Answer: Option B
Explanation: The & operator performs intersection and returns common elements between sets.
Q7
Which method removes and returns an arbitrary element from a set?
Answer: Option C
Explanation: pop() removes and returns an arbitrary element from the set. Raises KeyError if set is empty.
Q8
What is the main characteristic of sets in Python?
Answer: Option C
Explanation: Sets are unordered collections of unique elements. They don't allow duplicates and are mutable.
Q9
Which of these is a frozen set?
Answer: Option C
Explanation: frozenset() creates an immutable set that cannot be modified after creation.
Q10
What does the symmetric_difference() method return?
Answer: Option C
Explanation: Symmetric difference returns elements that are in either set but not in their intersection.