Sets Questions and Answers
Python Programming - Sets Questions with Answers explain how to handle collections of unique items efficiently. These Python Sets Questions are useful for Infosys, IBM, and SSC exams covering Python’s mathematical data operations
Sets
Showing 10 of
25 questions
2. What is the output of: set([1, 2, 3, 2, 1])?
- [1, 2, 3]
- {1, 2, 3}
- {1, 2, 3, 2, 1}
- Error
4. What does the union() method do for sets?
- Combines two sets and returns common elements
- Combines two sets and returns all unique elements
- Removes common elements from both sets
- Updates the first set with elements from second set
6. What is the result of: {1, 2, 3} & {2, 3, 4}?
- {1, 2, 3, 4}
- {2, 3}
- {1, 4}
- {1, 2}
7. Which method removes and returns an arbitrary element from a set?
- remove()
- discard()
- pop()
- delete()
8. What is the main characteristic of sets in Python?
- Ordered and indexed
- Allow duplicate elements
- Unordered and unique elements
- Immutable once created
9. Which of these is a frozen set?
- set([1, 2, 3])
- {1, 2, 3}
- frozenset([1, 2, 3])
- All of the above
10. What does the symmetric_difference() method return?
- Common elements only
- Elements in first set but not in second
- Elements in either set but not both
- All elements from both sets