Python frozenset Data Type (PYTHON FUNDAMENTALS)

Created with Sketch.

  • It is exactly the same as set except that it is immutable.
  •  Hence we cannot use add or remove functions.
 >>> s={10,20,30,40} 
 >>> fs=frozenset(s) 
 >>> type(fs) 
 <class 'frozenset'> 
 >>> fs 
 frozenset({40, 10, 20, 30}) 
 >>> for i in fs:print(i) 
 
 40 
 10 
 20 
 30 
 
 >>> fs.add(70) 
 AttributeError: 'frozenset' object has no attribute 'add' 
 >>> fs.remove(10) 
 AttributeError: 'frozenset' object has no attribute 'remove' 

Leave a Reply

Your email address will not be published. Required fields are marked *