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 String split()
Python iter()
Python bool()
Python List pop()
Python enumerate()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python datetime
Python Multiple Inheritance
Python dir()
Python Program to Check if a Number is Positive, Negative or 0
Python Dictionary clear()
Python Program to Represent enum
Python String zfill()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Python Program to Create a Countdown Timer
Python Program to Make a Flattened List from Nested List
Python open()
Python Program to Sort Words in Alphabetic Order
Python Variables, Constants and Literals
Python String rpartition()
Python Decorators
Python String istitle()
Python sleep()
Python Program to Multiply Two Matrices
Python Program to Measure the Elapsed Time in Python
Python String isdecimal()
Python Program to Split a List Into Evenly Sized Chunks
Python Program Read a File Line by Line Into a List
Python Closures
Python frozenset()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey