frozenset(iterable=set())
Returns an immutable set.
Parameters
The frozenset() function takes one parameter:
iterable(optional) — an iterable containing elements to initialize the frozen set. The iterable can be a set, dictionary, tuple, etc.
Return Value
- The
frozenset()function returns an immutablefrozenset, initialized with elements from the given iterable. - If no parameters are passed, it returns an empty
frozenset.
Examples
# Tuple of vowels
vowels = ('i', 'e', 'i', 'o', 'u')
fSet = frozenset(vowels)
print('The frozen set is:', fSet)
print('The empty frozen set is:', frozenset())
# Frozen sets are immutable
fSet.add('v')
# Output:
# The frozen set is: frozenset({'i', 'e', 'o', 'u'})
# The empty frozen set is: frozenset()
# Traceback (most recent call last):
# File "<string>", line 9, in <module>
# AttributeError: 'frozenset' object has no attribute 'add'