{"id":25055,"date":"2021-11-10T09:37:22","date_gmt":"2021-11-10T04:07:22","guid":{"rendered":"https:\/\/python-programs.com\/?p=25055"},"modified":"2021-11-10T09:37:22","modified_gmt":"2021-11-10T04:07:22","slug":"python-set-difference_update-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-set-difference_update-method-with-examples\/","title":{"rendered":"Python Set difference_update() Method with Examples"},"content":{"rendered":"
Prerequisite:<\/h5>\n

Python set() Function with Examples<\/span><\/a><\/p>\n

Set difference_update() Method in Python:<\/strong><\/p>\n

The difference_update() method removes items from both sets.<\/p>\n

The difference_update() method differs from the difference() method in that the difference() method returns a new set that does not include the unwanted items, whereas the difference_update() method removes the unwanted items from the original set.<\/p>\n

For Example<\/strong><\/p>\n

If P and Q are two distinct sets. A set difference between P and Q is a set of elements that exist only in set P but not in set Q.<\/p>\n

The difference_update() replaces set P with the P-Q set difference.<\/p>\n

Syntax:<\/strong><\/p>\n

set.difference_update(set)<\/pre>\n

Parameters<\/strong><\/p>\n

set:<\/strong> This is Required. The set used to look for differences.<\/p>\n

Return Value:<\/strong><\/p>\n

difference_update() produces a result None, indicating that the object (set) has been mutated.<\/p>\n

Let P, Q be two sets<\/p>\n

When you execute the code,<\/p>\n