w3resource

Python: frozenset() function

frozenset() function

The frozenset() function returns a new frozenset object, optionally with elements taken from iterable.

Note: frozenset is a built-in class.

Version:

(Python 3.2.5)

Syntax:

frozenset([iterable])

Parameter:

Name Description Required /
Optional
iterable An iterable object, like list, set, tuple etc. Required

Return value:

frozenset object.

Example: Python frozenset() function

# tuple of words
words = ('apple', 'orange', 'mango', 'banana')

froSet = frozenset(words)
print('The frozen set is:', froSet)
print('The empty frozen set is:', frozenset())

Output:

The frozen set is: frozenset({'apple', 'mango', 'orange', 'banana'})
The empty frozen set is: frozenset()

Pictorial Presentation:

Python: Built-in-function - frozenset() function

Python Code Editor:

Previous: format()
Next: getattr()

Test your Python skills with w3resource's quiz



Python: Tips of the Day

How do I check if a list is empty?

For example, if passed the following:

a = []
if not a:
  print("List is empty")

Ref: https://bit.ly/2A4JXx9