Metoda Python symmetric_difference () vrací symetrický rozdíl dvou sad.
Symetrický rozdíl dvou množin A a B je množina prvků, které jsou buď v A nebo B, ale ne v jejich průsečíku.

Syntaxe symmetric_difference()
je:
A.symmetric_difference (B)
Příklad 1: Práce symmetric_difference ()
A = ('a', 'b', 'c', 'd') B = ('c', 'd', 'e' ) C = () print(A.symmetric_difference(B)) print(B.symmetric_difference(A)) print(A.symmetric_difference(C)) print(B.symmetric_difference(C))
Výstup
('b', 'a', 'e') ('b', 'e', 'a') ('b', 'd', 'c', 'a') ('d', 'e ',' c ')
Symetrický rozdíl pomocí operátoru ^
V Pythonu můžeme také najít symetrický rozdíl pomocí ^
operátoru.
A = ('a', 'b', 'c', 'd') B = ('c', 'd', 'e' ) print(A B) print(B A) print(A A) print(B B)
Výstup
('e', 'a', 'b') ('e', 'a', 'b') set () set ()