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 bytearray()
Python hash()
Python Set copy()
Python memoryview()
Python strptime()
Python locals()
Python str()
Python break and continue
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program Read a File Line by Line Into a List
Python List copy()
Python type()
Python String count()
Python Program to Make a Simple Calculator
Python String join()
Python Program to Transpose a Matrix
Python String index()
Python Program to Find Numbers Divisible by Another Number
Python String rfind()
Python String isalpha()
Python Program to Get the Full Path of the Current Working Directory
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python input()
Python hex()
Python pow()
Python Dictionary clear()
Python issubclass()
Python Program to Get the Class Name of an Instance
Python range()
Python iter()
Python vars()
Python Generators