{"id":24874,"date":"2021-11-10T09:36:39","date_gmt":"2021-11-10T04:06:39","guid":{"rendered":"https:\/\/python-programs.com\/?p=24874"},"modified":"2021-11-10T09:36:39","modified_gmt":"2021-11-10T04:06:39","slug":"python-frozenset-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-frozenset-function-with-examples\/","title":{"rendered":"Python frozenset() Function with Examples"},"content":{"rendered":"

frozenset() Function in Python:<\/strong><\/p>\n

The frozenset() function returns an immutable frozenset object that has been initialized with elements from the iterable passed in.<\/p>\n

A frozen set is nothing more than an immutable version of a Python set object. While elements of a set can be changed at any time, elements of a frozen set do not change after they are created.<\/p>\n

As a result, frozen sets can be used as Dictionary keys or as elements of another set. However, it is not ordered in the same way that sets are (the elements can be set at any index).<\/p>\n

Syntax:<\/strong><\/p>\n

frozenset(iterable)<\/pre>\n

Parameters<\/strong><\/p>\n

The frozenset() function only accepts one parameter:<\/p>\n

iterable:<\/strong> This is Optional. The iterable contains the elements to be used to initialize the frozenset.<\/p>\n

Iterable types include set, dictionary, tuple, and so on.<\/p>\n

Return Value:<\/strong><\/p>\n

The frozenset() function returns an immutable frozenset that has been initialized with elements from the specified iterable.<\/p>\n

It returns an empty frozenset if no parameters are passed.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = ['good', 'morning', 'btechgeeks']<\/pre>\n

Output:<\/strong><\/p>\n

The Given list's frozenset = frozenset({'morning', 'good', 'btechgeeks'})\r\nAn empty frozenset =  frozenset()<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given dictionary = {\"hello\": 12, \"this\": 14, \"is\": 10, \"btechgeeks\": 20}<\/pre>\n

Output:<\/strong><\/p>\n

The Given dictionary's frozenset :\r\nfrozenset({'btechgeeks', 'is', 'hello', 'this'})<\/pre>\n

frozenset() Function with Examples in Python<\/h2>\n