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 for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Dictionary keys()
Python dict()
Python Package
Python set()
Python all()
Python Program to Get the Full Path of the Current Working Directory
Python delattr()
Python String isidentifier()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python String endswith()
Python Program to Find the Square Root
Python complex()
Python Program to Represent enum
Python Set clear()
Python print()
How to get current date and time in Python?
Python Program to Shuffle Deck of Cards
Python Program to Find the Factors of a Number
Python Program to Find the Factorial of a Number
Python Program to Extract Extension From the File Name
Python float()
Python Exception Handling Using try, except and finally statement
Python Shallow Copy and Deep Copy
Python Program to Find Armstrong Number in an Interval
Python frozenset()
Python setattr()
Python String startswith()
Python Program to Create Pyramid Patterns
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String isdecimal()
Python Set intersection_update()