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 Program to Count the Occurrence of an Item in a List
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python property()
Python String upper()
Python abs()
Python Global, Local and Nonlocal variables
Python format()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Merge Two Dictionaries
Python Package
Python Program to Iterate Over Dictionaries Using for Loop
Deep Learning in Python - LazyProgrammer
Python round()
Python Program to Check If Two Strings are Anagram
Python Set issuperset()
Python Program to Convert Bytes to a String
Python Tuple index()
Python Program to Check the File Size
Python Program to Multiply Two Matrices
Python super()
Python max()
Python String rjust()
Python int()
Python Shallow Copy and Deep Copy
Python Set isdisjoint()
Python Program to Measure the Elapsed Time in Python
Python __import__()
Python Program to Randomly Select an Element From the List
Python Program to Add Two Matrices
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Find the Size (Resolution) of a Image
Python String format()