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 list()
Python String rpartition()
Python Program to Return Multiple Values From a Function
Python Program to Find the Sum of Natural Numbers
Python String isdigit()
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Parse a String to a Float or Int
Python Program to Find Hash of File
Python Program to Check If a List is Empty
Python List append()
Python Namespace and Scope
Python Program to Illustrate Different Set Operations
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python len()
Python strptime()
Python Program to Trim Whitespace From a String
Convert a Map to an Array, List or Set in Java
Python Set symmetric_difference_update()
Node.js vs Python for Backend Development
Python Strings
Python List sort()
Python Program to Merge Two Dictionaries
Python Program to Delete an Element From a Dictionary
Python String isdecimal()
Python String splitlines()
Python Program to Convert Bytes to a String
Python issubclass()
Python Dictionary pop()
Python String index()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python String rsplit()