difference_update() method in Python set

All set methods

Update the main set with difference elements only ( after removing common elements ).

Using difference_update() method

A={'a','b','c'}
B={'a','y','z'}
A.difference_update(B)
print(A)
Output
{'c','b'}

Using more than one sets

We can use any number of sets with difference_update()
A={'a','b','c'}
B={'a','y','z'}
C={'a','c','l'}
A.difference_update(B,C)
print(A)
Output
{'b'}

difference_update() method

Using string ( iterable object ) with difference_update() method
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 Questions with solutions on set
difference() union() intersection() symmetric_difference()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer