Frozen set methods
Creates a shallow copy of the frozenset (or set), returning a new frozenset (or set) with the same elements.
Syntax: frozensetobj2 = frozensetobj1.copy()
- Since frozenset is immutable, the copy is identical but independent (no practical difference in immutability).
- For set, the copy is mutable and can be modified independently.
fs1 = frozenset([1, 2, 3])
fs2 = fs1.copy()
print(fs2) # frozenset({1, 2, 3})
# fs2 is a new frozenset, but immutable like fs1
Returns True if two frozenset objects (or set objects) have no common elements; otherwise, False.
Syntax: frozensetobj1.isdisjoint(frozensetobj2).
fs1 = frozenset([1, 2, 3])
fs2 = frozenset([4, 5, 6])
fs3 = frozenset([2, 7, 8])
print(fs1.isdisjoint(fs2)) # True (no common elements)
print(fs1.isdisjoint(fs3)) # False (2 is common)
Returns True if frozensetobj1 contains all elements of frozensetobj2; otherwise, False.
- Syntax: frozensetobj1.issuperset(frozensetobj2)