frozenset() in Python

By Hemanta Sundaray on 2021-08-22

Learn about the Python set data structure in my blog post here.

We can create an immutable set (a set that can’t be changed) using the frozenset() function and passing it any iterable argument.

If we will try to add an item to a set created using the frozenset() function, we will receive an AttributeError, as shown below:

states = frozenset(['Washington', 'Texas', 'Florida'])

states.add('California')
# AttributeError: 'frozenset' object has no attribute 'add'

Join the Newsletter