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 Convert Kilometers to Miles
Python divmod()
Python Program to Trim Whitespace From a String
Python Program to Add Two Matrices
Python Inheritance
Python Set copy()
Python Tuple count()
Python Set clear()
Python List count()
Python Program to Iterate Over Dictionaries Using for Loop
Python Program to Delete an Element From a Dictionary
Python Program to Print all Prime Numbers in an Interval
Python Set issuperset()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Get Current time
Python bool()
Python String rfind()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Extract Extension From the File Name
Python Program to Safely Create a Nested Directory
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Print Output Without a Newline
Python Program to Represent enum
Python Set isdisjoint()
Python iter()
Python Program to Check Leap Year
Python Package
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Count the Number of Digits Present In a Number
Python Global Keyword
Python Program to Get File Creation and Modification Date