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 Decorators
Python hash()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Display Fibonacci Sequence Using Recursion
Python slice()
Python Program to Check if a Number is Odd or Even
Python String isprintable()
Python List reverse()
Python Objects and Classes
Python Program to Get a Substring of a String
Python Program to Find the Factors of a Number
Python repr()
Python Program to Find Armstrong Number in an Interval
Python Dictionary
Python Program to Get the File Name From the File Path
Python Program to Convert Celsius To Fahrenheit
Python Program to Find HCF or GCD
Python pow()
Python Program to Copy a File
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Java Program to Implement Dijkstra’s Algorithm using Set
Python Program to Get Line Count of a File
Python enumerate()
Python tuple()
Python object()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python globals()
Python Program to Differentiate Between type() and isinstance()
Python Tuple index()
Python bytearray()
Python Program to Delete an Element From a Dictionary
Python frozenset()