English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Função do Python

Tipos de Dados do Python

Python File Operations

Python Objects and Classes

Python Date and Time

Advanced Python Knowledge

Python Reference Manual

Python set symmetric_difference_update() usage and example

Métodos do Conjunto do Python

The symmetric_difference_update() method finds the symmetric difference set of two sets and updates the set it calls.

The symmetric difference of two sets A and B is the set of elements that are in A or B but not in their intersection.

The syntax of symmetric_difference_update() is:

A.symmetric_difference_update(B)

symmetric_difference_update() return value

  • symmetric_difference_update() returns None (does not return any content). And it updates the set it calls.

Example: the working of symmetric_difference_update()

A = {'a', 'c', 'd'}
B = {'c', 'd', 'e'}
result = A.symmetric_difference_update(B)
print('A =', A)
print('B =', B)
print('result =', result)

Output result

A = {'a', 'e'}
B = {'d', 'c', 'e'}
result = None

Here, set A is updated to the symmetric difference of set A and set B. But set B does not change.

Recommended reading: Python Set symmetric_difference()

Métodos do Conjunto do Python