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 complex()
Python Program to Find HCF or GCD
Python Program to Count the Occurrence of an Item in a List
Python isinstance()
Python issubclass()
Python List pop()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Object Oriented Programming
Python Program to Reverse a Number
Python oct()
Python Dictionary keys()
Python sleep()
Python if...else Statement
Python Dictionary clear()
Python Program to Get the File Name From the File Path
Python Program to Check If a List is Empty
Python String startswith()
Python String isupper()
Python Matrices and NumPy Arrays
Python type()
Converting Between a List and a Set in Java
Python Generators
Python datetime
Python callable()
Python Program to Display the multiplication Table
Python Set update()
Python input()
Python round()
Python Program to Find Hash of File
Python Program to Print the Fibonacci sequence
Python all()
Python Program to Convert Two Lists Into a Dictionary