Python Set Methods
Set methods add, remove, or do set algebra. add(x) inserts one. update(...) adds many. remove(x) errors if x is missing. discard(x) stays quiet. pop() removes an arbitrary item. union / intersection / difference / symmetric_difference match | & - ^ . issubset / issuperset / isdisjoint test relationships.
MCQ — remove vs discard. remove(99) on a set without 99 → KeyError. discard(99) does nothing. Say that pair first.
Python Set Methods — output — {1, 2, 3}. discard(9) does nothing — no crash.
{1, 2, 2, 3}
│ unique
▼
{1, 2, 3}remove raises; discard stays quiet.