Python set symmetric_difference_update() Method

A.symmetric_difference_update(other) changes A so it keeps elements present in exactly one of the two collections. It returns None and modifies the original set.

Use symmetric_difference() or ^ when you need a new set instead of changing the original mutable set.

Set order: sets are unordered. Whenever an example prints a set, the displayed element order can differ between runs or Python environments.

  • Video Tutorial on Set


set operation difference

Using symmetric_difference_update() method

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

symmetric_difference_update() method

Using string ( iterable object ) with symmetric_difference_update() method
A={'a','b','c','x','y'}
B='Alex'
A.symmetric_difference_update(B)
print(A)
Output
{'y', 'l', 'A', 'e', 'b', 'a', 'c'}
Using list with symmetric_difference_update() method.
A={'a','b','c'}
B=['a','x','y']
A.symmetric_difference_update(B)
print(A)
Output
{'y', 'x', 'b', 'c'}
All Set Methods Updating Set Operations Questions with solutions on set
difference() union() intersection() symmetric_difference()


Subscribe to our YouTube Channel here



plus2net.com







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 Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer