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 Check the File Size
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Decorators
Python sorted()
Python Program to Convert Kilometers to Miles
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python int()
Python Generators
Python Program to Return Multiple Values From a Function
Python hasattr()
Python List copy()
Python Global, Local and Nonlocal variables
Python any()
Python Set discard()
Python Numbers, Type Conversion and Mathematics
Python setattr()
Python List Comprehension
Python Package
Python List
Python Program to Get the File Name From the File Path
Python compile()
Python Program to Find the Square Root
Python while Loop
Python Program to Get a Substring of a String
Python List count()
Python frozenset()
Python complex()
Python Program to Check Prime Number
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Check if a Number is Odd or Even
Python String count()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...