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
1. Which of the following creates an empty set in Python?
  • {}
  • set()
  • []
  • ()
Show Answer Report
2. What is the output of: set([1, 2, 3, 2, 1])?
  • [1, 2, 3]
  • {1, 2, 3}
  • {1, 2, 3, 2, 1}
  • Error
Show Answer Report
3. Which method adds an element to a set?
  • append()
  • insert()
  • add()
  • push()
Show Answer Report
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
Show Answer Report
5. Which operator is used for set difference in Python?
  • -
  • &
  • |
  • ^
Show Answer Report
6. What is the result of: {1, 2, 3} & {2, 3, 4}?
  • {1, 2, 3, 4}
  • {2, 3}
  • {1, 4}
  • {1, 2}
Show Answer Report
7. Which method removes and returns an arbitrary element from a set?
  • remove()
  • discard()
  • pop()
  • delete()
Show Answer Report
8. What is the main characteristic of sets in Python?
  • Ordered and indexed
  • Allow duplicate elements
  • Unordered and unique elements
  • Immutable once created
Show Answer Report
9. Which of these is a frozen set?
  • set([1, 2, 3])
  • {1, 2, 3}
  • frozenset([1, 2, 3])
  • All of the above
Show Answer Report
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
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test