A={1,2,3}
B={3,4,5}
print(A ^ B)
Output ( Note 3 is the only common element so all elements without 3 is returned.)
{1, 2, 4, 5}
A={1,2,3}
B={3,4,5}
x=A ^ B
print(type(x))
Output
<class 'set'>
A={'a','b','c'}
B={'a','y','z'}
print(A.symmetric_difference(B))
Output
{'b', 'y', 'z', 'c'}
A={'a','b','c'}
B={'a','y','z'}
C={'a','k','l'}
print(A ^ B ^ C)
Output
{'y', 'a', 'l', 'b', 'k', 'z', 'c'}
A={'a','b','c','x','y'}
B='Alex'
print(A.symmetric_difference(B))
Output
{'y', 'a', 'l', 'e', 'A', 'b', 'c'}
A={'a','b','c'}
B=['a','x','y']
print(A.symmetric_difference(B))
Output
{'b', 'x', 'c', 'y'}
Below code will generate error.
print(A ^ B)
TypeError: unsupported operand type(s) for ^: 'set' and 'list'
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.