BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Set symmetric_difference_update() method

Last Updated: April 1, 2019 by Chaitanya Singh | Filed Under: Python Tutorial

In the last tutorial we discussed symmetric_difference() method which returns a new set which is a symmetric difference of two given sets. Here we will discuss, symmetric_difference_update() method which does not return anything but it updates the calling set with the symmetric difference set. For example calling this method like this A.symmetric_difference_update(B) would update set A with the symmetric difference set.

Set symmetric_difference_update() Syntax

set.symmetric_difference_update(another_set)

Parameter: It takes a set as a parameter
Return Value: It does not return anything, it just updates the calling set.

Python Set symmetric_difference_update() Example

In the following example we have two sets X and Y. We are calling symmetric_difference_update() method like this X.symmetric_difference_update(Y) which finds the symmetric difference between X and Y, which contains the elements that are either in Set X or in Set Y but not in both, this method then updates the calling set X with the symmetric difference.

# Set X
X = {1, 2, 3}

# Set Y
Y = {2, 3, 4}

# Before calling symmetric_difference_update()
print("Set X is:", X)
print("Set Y is:", Y)

# calling symmetric_difference_update() method
X.symmetric_difference_update(Y)

# After calling symmetric_difference_update()
print("Set X is:", X)
print("Set Y is:", Y)

Output:
Python symmetric_difference_update() method example

Top Related Articles:

  1. Python Set update() method with examples
  2. Python Data Types
  3. Python Recursion
  4. Python Keywords and Identifiers with examples
  5. Python Constructors – default and parameterized

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap