The difference_update() updates the set calling difference_update() method with the difference of sets.
If A and B are two sets. The set difference of A and B is a set of elements that exists only in set A but not in B.
To learn more, visit Python set difference.
The syntax of difference_update() is:
A.difference_update(B)
Here, A and B are two sets. difference_update() updates set A with the set difference of A-B.
1. Return Value from difference_update()
difference_update() returns None indicating the object (set) is mutated.
Suppose,
result = A.difference_update(B)
When you run the code,
- result will be
None - A will be equal to A-B
- B will be unchanged
2. Example: How difference_update() works?
A = {'a', 'c', 'g', 'd'}
B = {'c', 'f', 'g'}
result = A.difference_update(B)
print('A = ', A)
print('B = ', B)
print('result = ', result)
Output
A = {'d', 'a'}
B = {'c', 'g', 'f'}
result = None
Related posts:
Python frozenset()
Python List count()
Python bool()
Python strptime()
Python Program to Delete an Element From a Dictionary
Python tuple()
Python Set add()
Python timestamp to datetime and vice-versa
Python chr()
Python Program to Display the multiplication Table
Python zip()
Python Program to Check if a Number is Odd or Even
Python Program to Find ASCII Value of Character
Python String find()
Python hex()
Python Program to Measure the Elapsed Time in Python
Python String isidentifier()
Python while Loop
Python Data Types
Python Program to Check Whether a String is Palindrome or Not
Python Program to Get File Creation and Modification Date
Python Program to Shuffle Deck of Cards
Python @property decorator
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Get Line Count of a File
Python Program to Convert Kilometers to Miles
Python String count()
Python isinstance()
Python Set difference()
Python Program to Find LCM
Python Program to Create Pyramid Patterns
Python Machine Learning - Sebastian Raschka