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 String maketrans()
Python String isnumeric()
Python List copy()
Python object()
Python hasattr()
Python Set symmetric_difference_update()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python String partition()
Python Program to Reverse a Number
Python Errors and Built-in Exceptions
Python hash()
Python setattr()
Python String endswith()
Python Closures
Python Dictionary setdefault()
Python String count()
Python Inheritance
Python compile()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python String zfill()
Python divmod()
Python String casefold()
Python Program to Print Colored Text to the Terminal
Python String find()
Python Program to Slice Lists
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python print()
Python Program to Illustrate Different Set Operations
Python Variables, Constants and Literals
Python Program to Split a List Into Evenly Sized Chunks
Python Input, Output and Import