What is a frozen set in Python?

A set is an unordered or unindexed “bag” of unique values.

A single set can contain values of any immutable datatype, meaning the values can’t be changed. A set itself is a mutable object, i.e, an object that can be changed after it is created.

Frozen sets

Frozen sets in Python return an object that is unchangeable. They are referred to as a set because the set is inherent, not mutable.

You can use the frozenset() function to get a non-mutable object.

Code

lst = ["a", "b","c"]
print("Normal List")
print(lst)
frozen_set = frozenset(lst)
print("\nFrozen Set")
print(frozen_set)
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources