A.difference_update(*others) removes from A every element found in the other iterables and returns None. It changes the original set in place because sets are mutable.
If you need a new result while keeping A unchanged, use difference() or the - operator.
A={'a','b','c'}
B={'a','y','z'}
A.difference_update(B)
print(A)
Output
{'c','b'}
A={'a','b','c'}
B={'a','y','z'}
C={'a','c','l'}
A.difference_update(B,C)
print(A)
Output
{'b'}
A={'a','b','c','x','y'}
B='Alex'
A.difference_update(B)
print(A)
Output
{'c', 'y', 'a', 'b'}
Using list with difference_update() method.
A={'a','b','c'}
B=['a','x','y']
A.difference_update(B)
print(A)
Output
{'c', 'b'}
All Set Methods Updating Set Operations Questions with solutions on set Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.