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 bool()
Python Program to Count the Number of Digits Present In a Number
Python Program to Check Leap Year
Python Set update()
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Trim Whitespace From a String
Python Set remove()
Python Program to Count the Occurrence of an Item in a List
Python getattr()
Python Program to Find Factorial of Number Using Recursion
Python eval()
Python Dictionary copy()
Python Program to Print Output Without a Newline
Python issubclass()
Python Set pop()
Python Errors and Built-in Exceptions
Python String maketrans()
Python Program to Check the File Size
Python @property decorator
Python List reverse()
Python Program to Find HCF or GCD
Convert a Map to an Array, List or Set in Java
Python strptime()
Python Program to Find the Largest Among Three Numbers
Python List remove()
Python Program to Get Line Count of a File
Python Set intersection_update()
Python enumerate()
Python Set copy()
Python Program to Calculate the Area of a Triangle
Python bytes()
Python String rstrip()