HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-21
1 <h2>Making operations on sets as methods</h2>
1 <h2>Making operations on sets as methods</h2>
2 <p>You've already learned about operators that allow you to combine sets. These operators are as similar as possible to those used in set theory in mathematics. Every programmer should at least know the basics of set theory. For this reason, we should use sets in combination with operators.</p>
2 <p>You've already learned about operators that allow you to combine sets. These operators are as similar as possible to those used in set theory in mathematics. Every programmer should at least know the basics of set theory. For this reason, we should use sets in combination with operators.</p>
3 <p>However, we should mention that each operator has a verbal equivalent method:</p>
3 <p>However, we should mention that each operator has a verbal equivalent method:</p>
4 <h2>Updating of sets in place</h2>
4 <h2>Updating of sets in place</h2>
5 <p>There is another reason why we're talking about the four methods above. Remember, we looked at the dictionary update method, updating the dictionary locally using data from another dictionary? There are several of these sorts of update methods.</p>
5 <p>There is another reason why we're talking about the four methods above. Remember, we looked at the dictionary update method, updating the dictionary locally using data from another dictionary? There are several of these sorts of update methods.</p>
6 <h3>The difference_update method</h3>
6 <h3>The difference_update method</h3>
7 <p>The difference_update works similarly to - or difference. It removes from the set all elements that are in the set argument of the associated one:</p>
7 <p>The difference_update works similarly to - or difference. It removes from the set all elements that are in the set argument of the associated one:</p>
8 <h3>The intersection_update method</h3>
8 <h3>The intersection_update method</h3>
9 <p>The intersection_update is the modifying analog of &amp; or intersection. It leaves only those elements in the linked set that are in the argument set:</p>
9 <p>The intersection_update is the modifying analog of &amp; or intersection. It leaves only those elements in the linked set that are in the argument set:</p>
10 <h3>The symmetric_difference_update method</h3>
10 <h3>The symmetric_difference_update method</h3>
11 <p>The symmetric_difference_update is the modifying analog of ^ or symmetric_difference. It adds elements to the linked set that are only in the argument and removes elements that are in both sets:</p>
11 <p>The symmetric_difference_update is the modifying analog of ^ or symmetric_difference. It adds elements to the linked set that are only in the argument and removes elements that are in both sets:</p>
12 <h3>The update method</h3>
12 <h3>The update method</h3>
13 <p>The update is the modifying equivalent of | or union. It complements the associated set with missing elements from the argument set:</p>
13 <p>The update is the modifying equivalent of | or union. It complements the associated set with missing elements from the argument set:</p>
14 <p>Concerning uniformity, the update should have been called union_update. But we chose the more common name update because developers often use this name for similar methods in other collections.</p>
14 <p>Concerning uniformity, the update should have been called union_update. But we chose the more common name update because developers often use this name for similar methods in other collections.</p>