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 isalnum()
Python Program to Check if a Number is Odd or Even
Python Program to Capitalize the First Character of a String
Python Program to Iterate Through Two Lists in Parallel
Python Set intersection()
Python Program to Find the Factorial of a Number
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Tuple count()
Python String join()
Python Program to Get the Last Element of the List
Python String isprintable()
Python Namespace and Scope
Python zip()
Python String expandtabs()
Python String translate()
How to get current date and time in Python?
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Display Calendar
Python Tuple index()
Python Program to Find the Size (Resolution) of a Image
Python Program to Extract Extension From the File Name
Python Program to Check Whether a String is Palindrome or Not
Python ord()
Python len()
Python String index()
Python Numbers, Type Conversion and Mathematics
Python Program to Merge Mails
Python List append()
Python Set symmetric_difference_update()
Python String isdigit()