beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Python Set symmetric_difference_update() method

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

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

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap