In this Python set program, we will create a frozen set in Python with the help of the below-given steps.
What is set?
Sets are used to store multiple items in a single variable.
The set is one of 4 built-in data types in Python used to store collections of data.
It is an unordered collection data type that is iterable, mutable and has no duplicate elements.
Frozen set: It is an immutable version of a Python set object. We can not make changes in the set after it is created.
Create a Frozen set in Python:
Steps to solve the program
1. Create a set using {}.
2. Add some elements in the set.
3. Create a frozen set using the frozenset() function.
4. Print the type of the new set to verify.
a = {1, 2, 4, 5, 7, 8, 9}
print("Original set1: ",a)
b = frozenset(a)
print(b)
Output :
Original set1: {1, 2, 4, 5, 7, 8, 9}
frozenset({1, 2, 4, 5, 7, 8, 9})
Related Articles
Python program to find the difference between multiple sets.
Python program to find the intersection between multiple sets.
Python program to check if any element in a set is a substring of a given string.
Python program to check if any element in a set is a prefix of a given string.
Python program to check if any element in a set is a suffix of a given string.
Python program to find the index of an element in a set.