×

Python Set symmetric_difference_update() method

Python Set symmetric_difference_update() method

The set.symmetric_difference_update() method in Python updates the original set by removing items that are present in both sets and inserting the other items of the set.

Syntax

set.symmetric_difference_update(set1)

Parameter

set- This parameter represents the first set that is used for checking the matches.

set1- This parameter represents the second set that is also used for checking the matches.

Return

None

Example 1

# Python program explaining
# the set.symmetric_difference_update() method
#initializing set1
set1 = {"mango", "banana", "apple","tomato"} 
print("Set 1:",set1)
# initializing set2
set2 = {"potato", "spinach","Carrot", "apple"} 
print("Set 2:",set2)
# updates the original set by removing items that are present in both sets
set1.symmetric_difference_update(set2) 
print("\nAfter the symmetric_difference_update() method...\n") 
# printing the updated new set
print("Updated Set 1:",set1)
# no change occurs at second set
# the second set remains the same
print("Set 2:",set2) 

Output

Set 1: {'banana', 'apple', 'tomato', 'mango'}
Set 2: {'spinach', 'potato', 'Carrot', 'apple'}
After the symmetric_difference_update() method...
Updated Set 1: {'potato', 'tomato', 'mango', 'banana', 'spinach', 'Carrot'}
Set 2: {'spinach', 'potato', 'Carrot', 'apple'} 

Example 2

# Python program explaining
# the set.symmetric_difference_update() method
# initializing the set1
set1 = {1,2,3,4,5,6} 
# initializing the set2
set2 = {2,7,8,6,5}
# updates the original set by removing items that are present in both sets
set1.symmetric_difference_update(set1) # passing same sets in both the arguments 
# printing the updated set
# will return set() as it deletes the common values.
print("Updated Set 1:", set1)
# no change in set2
print("Set 2:",set2) 

Output

Updated Set 1: set()
Set 2: {8, 2, 5, 6, 7}

Related Topics

Python Maurer Rose and Rhodonea Curves

In this tutorial, in Python we will make a Maurer Rose example and Rhodonea Curve example. Before we continue to see what precisely is maurer rose or a rhodonea bend...

10 minutes read.

Managing Multiple Python Versions With pyenv

Introduction If you had ever wished to assist to an application that makes use of several different Python versions but weren't sure whether you would quickly test them all? Do you...

4 minutes read.

Simple GUI calculator using PyQt5 in Python

GUI: The user is provided with information using manipulable visual widgets that don't require command-line input. These interface components respond to the user's interactions per the pre-programmed script, assisting each user's...

4 minutes read.

How to Concatenate Two Strings in Python

How to Concatenate Two Strings in Python Like the other data types, operations on strings are quite useful when we deal with some real-life applications. Here we will talk about a simple...

4 minutes read.

Python Simple Interest

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

3 minutes read.

Python Line Break

Introduction In this tutorial, you will learn line breaks in python.In Python, the new line character is used to indicate the start of a new line and the end of an...

5 minutes read.

Executing Shell Commands in Python

This tutorial aims to make us understand what a Shell is, what is the importance of a Shell, what are Shell commands in Python, and how can we execute the...

3 minutes read.

Python Set update() method

Python Set update() method The set.update() method in Python updates the current set, by adding items from another set. If an element is common in both the sets, only one appearance of this item...

1 minute read.

Type casting in Python

Introduction Type Casting is defined as the method of converting the variables/values data type into a certain data type for matching the operation needed to be performed by the users. This...

4 minutes read.

Python Built-in Functions

Python Built-in Functions The Python interpreter has a number of functions and types built into it that are always available. The Python built- in functions are as follow: Methods Explaining abs() The abs() function returns...

6 minutes read.

Python String splitlines() method

Python String splitlines() method The string.splitlines() method in Python splits the specified string and returns a list of the lines in the string, breaking at line boundaries.  Syntax splitlines([keepends]) Parameter keepends(optional): This parameter specifies if...

1 minute read.

Python History

Python is one of the top trending, widely-used programming languages. Python is a general-purpose programming language. Python language is known for its features. Some features are given below: SimplisticFree and open...

4 minutes read.

Python String encode() method

Python String encode() method The string.encode() method in Python returns an encoded version of the string. The default encoding is the current default string encoding Syntax String.encode([encoding[,errors]]) Parameter Encoding: This parameter represents a String specifying...

2 minutes read.

Python Dictionary values() method

Python Dictionary values() method The dictionary.values() method in Python returns a view object that displays a list of all the values in the specified dictionary. Syntax dictionary.values() Parameter NA Return This method returns a view object. The...

1 minute read.

Loan Calculator using PyQt5 in Python

In the following tutorial, we will learn how to build a Loan Calculator application using the PyQt5 library in the Python programming language. So, let's get started. Introduction to the code: The heading...

4 minutes read.

Python Program for Linear Search

Introduction We employ specific algorithms to efficiently carry out our responsibilities, such as searching for an element in a given data structure. These algorithms fall under the category of searching algorithms....

4 minutes read.

Flutter Python

The flutter is a frame work available in the python programming language, to create web applications, mobile apps. The flutter is generally used for the development of the backend of...

3 minutes read.

Difference between Perl and Python

Control and presently utilized for a great many undertakings, including framework organization, web improvement, network programming, and GUI improvement, and the sky is the limit from there. About Perl? Perl is a...

4 minutes read.

Data Structures and Algorithms using Python | Part 2

Files: A file is a location or information stored in computer storage devices. File handling is essential when the information or the data is to be held permanently. When we try to...

20 minutes read.

Check Palindrome in Python

Python is an object-oriented high-level programming language. Python has dynamic semantics and has high-level built-in data structures which support dynamic typing and dynamic binding. Python provides rapid development. It has...

4 minutes read.