This method is used to remove common items from set A, given that A.difference_update(B). All changes are done in the original set only no 3rd variable is involved in this method. Simply put, all it does is
A=A-B | All the operation done is stored in A itself.
All changes are done in the original set itself.
This method takes an argument
- A set is taken
- B set is taken
- difference_update() method is applied on set A using B
- Value of set A is printed
- A set is printed excluding common item from set B.
- What is difference between difference method and update difference method?
Difference method apply changes and result is stored in another variable, whereas in difference update method applied changes is stored in original set itself.
Definition: This method is used to return another set which is in A and not in B, meaning, A – B is applied and whatever remains in A will be passed into another variable. Also, the original set remains the unchanged. Syntax: Variable = set1.difference(set2) This method takes an argument. Working: Code: A set with …
Definition: This method in set is simply used to copy the entire set into another variable. Also, the original set remains unchanged. Syntax: Variable = set.copy() This method does not take any argument. Working: Code: A set is being taken with some values We have applied copy() method to that set and passed it to …
Definition: This method of a set is used to remove all the elements of the set and returns an empty set. Also, note that this method does not delete the set it only removes the set item. Syntax: set.clear() This method does not take any argument, a passing argument will throw an error. Working: Code: …