diff --git a/native-datatypes.html b/native-datatypes.html index 901ec49..11da33f 100644 --- a/native-datatypes.html +++ b/native-datatypes.html @@ -597,33 +597,32 @@ KeyError: 'pop from an empty set'
FIXME +
Python’s set type supports several common set operations.
>>> a_set = {2, 4, 5, 9, 12, 21, 30, 51, 76, 127, 195}
>>> 30 in a_set ①
True
->>> 31 in a_set ②
+>>> 31 in a_set
False
>>> b_set = {1, 2, 3, 5, 6, 8, 9, 12, 15, 17, 18, 21}
->>> a_set.union(b_set) ③
+>>> a_set.union(b_set) ②
{1, 2, 195, 4, 5, 6, 8, 12, 76, 15, 17, 18, 3, 21, 30, 51, 9, 127}
->>> a_set.intersection(b_set) ④
+>>> a_set.intersection(b_set) ③
{9, 2, 12, 5, 21}
->>> a_set.difference(b_set) ⑤
+>>> a_set.difference(b_set) ④
{195, 4, 76, 51, 30, 127}
->>> a_set.symmetric_difference(b_set) ⑥
+>>> a_set.symmetric_difference(b_set) ⑤
{1, 3, 4, 6, 8, 76, 15, 17, 18, 195, 127, 30, 51}
in operator. This works the same as lists.
+union() method returns a new set containing all the elements that are in either set.
+intersection() method returns a new set containing all the elements that are in both sets.
+difference() method returns a new set containing all the elements that are in a_set but not b_set.
+symmetric_difference() method returns a new set containing all the elements that are in exactly one of the sets.
FIXME +
Three of these methods are symmetric.
# continued from the previous example @@ -638,14 +637,14 @@ KeyError: 'pop from an empty set'>>> b_set.difference(a_set) == a_set.difference(b_set) ⑤ False
FIXME +
Finally, there are a few questions you can ask of sets.
>>> a_set = {1, 2, 3}
@@ -654,15 +653,15 @@ KeyError: 'pop from an empty set'
True
>>> b_set.issuperset(a_set) ②
True
->>> a_set.add(5)
->>> a_set.issubset(b_set) ③
+>>> a_set.add(5) ③
+>>> a_set.issubset(b_set)
False
>>> b_set.issuperset(a_set)
False
False.