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 Create Pyramid Patterns
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Deep Learning Cookbook - Indra den Bakker
Converting Between an Array and a Set in Java
Python Program to Access Index of a List Using for Loop
Python String capitalize()
Python String replace()
Python Matrices and NumPy Arrays
Python Program to Find Numbers Divisible by Another Number
Python Get Current time
Python Program Read a File Line by Line Into a List
Python sum()
Python *args and **kwargs
Python String isnumeric()
Python round()
Python strftime()
Python Anonymous / Lambda Function
Python Set union()
Python sorted()
Python hasattr()
Python bytearray()
Python Program to Randomly Select an Element From the List
Python int()
Python divmod()
Python list()
Python Program to Measure the Elapsed Time in Python
Python String isdecimal()
Python Program to Compute all the Permutation of the String
Python Program to Find Hash of File
Python id()
Python Program to Transpose a Matrix
Python Program to Check if a Number is Odd or Even