element
: matching element to be removed from setmy_set={'a','b','c','x','k'}
my_set.remove('x')
print(my_set)
Output is here
{'c', 'a', 'k', 'b'}
In above code x is deleted from my_set.
KeyError
my_set={'a','b','c','x','k'}
my_set.remove('y')
my_set={'a','b','c','x','k'}
my_set.discard('y')
print(my_set)
Output
{'x', 'c', 'a', 'k', 'b'}
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.