Python set symmetric_differential_clause ()

Python Methods and Functions


Symmetrical difference marked in green

The mmetric_difference () method returns a new set that contains the symmetric difference of the two sets. The symbric_difference_update () method updates the set calling symbric_difference_update () with the symmetric set difference.

Syntax:
A.symmetric_difference_update (B)
Parameters:
The symmetric_difference takes a single “set” as a argument.
Returns:
This method returns None (which indicates absence of a return value). It only updates the set calling symmetric_difference_update () with the symmetric difference of sets.

CODE 1

# Python code to demonstrate how it works
# mmetric_difference_update ()

  

A = { 'p' , ' a' , ' w' , 'a' , 'n' }

B = { 'r' , ' a' , 'o' , 'n' , ' e' }

 
# there is always no result.

result = A.symmetric_difference_update (B)

 

print ( 'A =' , A)

print ( 'B =' , B)

print ( 'result =' , result)

Output:

 
 ('A =', set (['e',' o', 'p',' r', 'w'])) (' B = ', set ([' a', 'r' , 'e',' o', 'n'])) (' result = ', None) 

Code 2

# Python code to demonstrate how it works
# mmetric_difference_update ()

  

A = { 's' , ' u' , 'n' , ' n' , 'y' }

B = { 'b ' , ' u' , 'n' , 'n' , ' y' }

 
# there is always no result.

result = A.symmetric_difference_update (B)

 

print ( 'A =' , A)

print ( 'B =' , B)

print ( 'result =' , result)

Output:

('A =', set (['s',' b'])) ('B =', set (['y',' b', 'u',' n'])) (' result = ', None)