Site icon i2tutorials

Frozenset() method in Python Built in Function

Frozenset() method in Python Built in Function

 

Frozenset method in built in function returns frozenset object which an immutable. It is initialized with the elements from the given Iterable.

 

Syntax:

class frozenset([iterable])

 

Parameter

frozenset method has single parameter.

  1. Iterable:this is an optional parameter which contains the elements to initialize the frozenset with. The Iterable can be set, list or tuple etc.

 

Example-1:

text = ['apple', 'guava', 'cherry']
x = frozenset(text)
print(x)

 

Output:

 

Using list in frozenset method

 

Example-2:

 

Using dictionary in frozenset method

person = {"name": "Jessie", "age": 23, "sex": "female"}
x = frozenset(person)
print('The frozen set is:', x)

 

Output:

Exit mobile version