{"id":3430,"date":"2022-11-26T14:15:43","date_gmt":"2022-11-26T14:15:43","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3430"},"modified":"2022-11-26T14:15:45","modified_gmt":"2022-11-26T14:15:45","slug":"python-set-symmetric-difference-update","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-set-symmetric-difference-update\/","title":{"rendered":"Python Set symmetric_difference_update() Method with examples"},"content":{"rendered":"<p style=\"text-align: center;\">Python Set symmetric_difference_update<\/p>\n<p>Now, we are going to learn about the <strong>\u00a0<\/strong>symmetric_difference_update method. Even before that, Let\u2019s have a quick revision of what we mean by symmetric difference operation. Let\u2019s say that we have two sets, set1, and set2.<\/p>\n<p>Now, if we do set1.symmetric_difference(set2), we get a new set, which is a symmetric difference between the two sets. By this, we simply mean that the new set is going to contain the elements that are in the given sets, but not in their intersection. But remember that with the symmetric_difference method, we get the new set.<\/p>\n<p>With the symmetric_difference_update method, we do not get a new set. Instead, the changes will be made on the set, that calls the method. For example, if we are doing set1.symmetric_difference_update(set2), the changes are made to set1. So, this method returns None.<\/p>\n<h2 style=\"text-align: center;\">Python Set symmetric_difference_update() Method<\/h2>\n<p>Let\u2019s have a look at a simple example, which demonstrates the symmetric_difference_update method.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3431 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-symmetric_difference_update-METHOD.jpg\" alt=\"\" width=\"642\" height=\"93\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-symmetric_difference_update-METHOD.jpg 642w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-symmetric_difference_update-METHOD-300x43.jpg 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/p>\n<p>As you can see in the above program, we have two sets, set1, and set2. Then we are trying to call the method symmetric_difference_update method on the set1, so the changes would be made to the set1. Also, in the last instruction, we are printing set1. So, the output in our case is going to be &#8211;<\/p>\n<p>{&#8216;W&#8217;, &#8216;Z&#8217;, &#8216;J&#8217;}<\/p>\n<p>As you can see, we got the changes into set1. So, as and when required, we can make use of the method symmetric_difference_update in our programs. Remember that the method does not return a new set. Instead, the changes are done to the set on which, the method was called<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python Set symmetric_difference_update Now, we are going to learn about the \u00a0symmetric_difference_update method. Even before that, Let\u2019s have a quick revision of what we mean by symmetric difference operation. Let\u2019s say that we have two sets, set1, and set2. Now, if we do set1.symmetric_difference(set2), we get a new set, which is a symmetric difference between [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3430","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3430"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3430\/revisions"}],"predecessor-version":[{"id":4119,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3430\/revisions\/4119"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}