If frozenset
objects are immutable, how is this possible:
>>> a = frozenset((1,2,3))
>>> a |= {2,3,4,5}
>>> print(a)
frozenset([1, 2, 3, 4, 5])
Note that the statement
>>> a |= {2,3,4,5}
does not change the frozenset
but rather creates a new one from the union of the old one and the set
{2,3,4,5}
. (In the same way, we have seen that for int
object i
, the assignment i = i + 1
rebinds the label i
to a the new integer object with value i+1
rather than changing the value of the immutable int
object previously bound to i
).