{"id":3433,"date":"2022-11-26T14:17:28","date_gmt":"2022-11-26T14:17:28","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3433"},"modified":"2022-11-26T14:17:29","modified_gmt":"2022-11-26T14:17:29","slug":"python-set-intersection_update","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-set-intersection_update\/","title":{"rendered":"Python Set intersection_update() Method with examples"},"content":{"rendered":"<p style=\"text-align: center;\">Python Set intersection_update<\/p>\n<p>Now, we are going to learn about the intersection_udpate method. First of all, Let\u2019s recall the intersection operation, which mostly we are familiar with. Let\u2019s consider that there are two sets, set1, and set2. So, if we do set1.intersection(set2), then we get a new set, which is an intersection of the two sets. By intersection, we mean that the new set is going to contain the elements that are common to all the sets. But remember that with the intersection method, we are getting a new set.<\/p>\n<h2 style=\"text-align: center;\">Python Set intersection_update() Method<\/h2>\n<p>Now, we are going to explore the intersection_update method, with which, we do not get a new set, but instead, the changes are made to the set on which the method is called. Let\u2019s have a look at the below example, which demonstrates the intersection_update method.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3434 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-intersection_update-METHOD.jpg\" alt=\"\" width=\"648\" height=\"111\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-intersection_update-METHOD.jpg 648w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-intersection_update-METHOD-300x51.jpg 300w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/p>\n<p>As you can see in the above program, we have two sets, set1, and set2. Then we are trying to find the intersection of the two sets. This time, we are using the intersection_update method, due to which, the updates are made to the set, on which the method is called (set with reference variable set1). In the last instruction, we are printing set1. So, Let\u2019s have a look at the output in our case.<\/p>\n<p>{&#8216;X&#8217;, &#8216;Y&#8217;}<\/p>\n<p>As you can see, since we are trying to get the intersection, we got those elements into the set, which are common to all the sets. The changes were made to the set1. So, as and when required, we can also make use of the intersection_update method in our python programs.<\/p>\n<p>So, this was about the set in python. We can make use of the set in our python programs, as and when required. Remember that the set can have only unique values, and we have seen some different operations that can be done on the sets here. You can practice some more programs related to sets so that you can get familiar with the concept of sets.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python Set intersection_update Now, we are going to learn about the intersection_udpate method. First of all, Let\u2019s recall the intersection operation, which mostly we are familiar with. Let\u2019s consider that there are two sets, set1, and set2. So, if we do set1.intersection(set2), then we get a new set, which is an intersection of the two [&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-3433","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\/3433","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=3433"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3433\/revisions"}],"predecessor-version":[{"id":4120,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3433\/revisions\/4120"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}