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 List
Python filter()
Python List count()
Python String lower()
Python Inheritance
Python Tuple index()
Python Program to Parse a String to a Float or Int
Python String lstrip()
Python Type Conversion and Type Casting
Python Program to Find Sum of Natural Numbers Using Recursion
Python String strip()
Python String upper()
Python Exception Handling Using try, except and finally statement
Python Program to Add Two Numbers
Python dir()
Python Operator Overloading
Python Program to Find the Sum of Natural Numbers
Python Sets
Python __import__()
Python map()
Python for Loop
Python String title()
Python Program to Get File Creation and Modification Date
How to get current date and time in Python?
Python String find()
Python bytes()
Python Program to Find the Largest Among Three Numbers
Python String count()
Python Program to Create Pyramid Patterns
Python slice()
Python max()
Python @property decorator