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 Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Return Multiple Values From a Function
Python Program to Add Two Matrices
Python Type Conversion and Type Casting
Python Program to Check if a Key is Already Present in a Dictionary
Python Set union()
Python vars()
Python String isalnum()
Python String casefold()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Exception Handling Using try, except and finally statement
Python Global Keyword
How to Get Started With Python?
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Access Index of a List Using for Loop
Python Closures
Python String title()
Python Program to Sort a Dictionary by Value
Python Operators
Python next()
Python Program to Find the Factorial of a Number
Python Program to Add Two Numbers
Python Program to Find the Largest Among Three Numbers
Python Generators
Python Dictionary items()
Python String islower()
Python Program to Differentiate Between type() and isinstance()
Python String isupper()
Python String istitle()
Python String center()
Python Set discard()
Python dir()