The function frozenset () in Python
frozenset () is a built-in function in Python, receiving input as an iterable object and returning the frozenset object unchanged.
Frozen set is an immutable version of a set object in Python, except that the element of the set can be modified at any time, while elements of the frozen set remain the same after creation.
Therefore, the frozenset can be used as a key in Dictionary or as a component of another set.
Syntax of frozenset () function in Python:
frozenset([iterable])
Parameters of function frozenset ()
- iterable: iterable contains elements to initialize frozenset. Iterable can be set, dictionary, tuple .
The value returned from frozenset ():
The method frozenset () returns a constant frozenset initialized with given iterable elements.
Example 1: How does frozenset () function work?
# tuple nguyen am nguyenam = ('a', 'e', 'i', 'o', 'u') fSet = frozenset(nguyenam) print('frozen set:', fSet)
Output returns:
frozen set: frozenset({'a', 'e', 'u', 'o', 'i'})
Example 2: frozenset () for Dictionary
# random dictionary person = {"ten": "Quach Tinh", "tuoi": 23, "gioi tinh": "nam"} fSet = frozenset(person) print('frozen set:', fSet)
Results returned:
frozen set: frozenset({'tuoi', 'gioi tinh', 'ten'})
See also: Built-in Python functions
4 ★ | 2 Vote
You should read it
May be interested
- Save your database with Recovery Toolbox for MySQLthere are no hardware requirements listed for recovery toolbox for mysql and the software requirements are also very simple.
- Do you know what programming language is?programming language is a type of computer language used to develop software programs, scripts, or standardization under a system of specific rules for computer execution.
- Overview of R language, install R on Windows and Linuxr is a very popular language, there are many reasons to start learning r and learn the benefits of this language.
- Formula to calculate trapezoidal area: normal, square, weightin the article below, tipsmake.com will work with you to learn some content related to the topic of trapezoid area calculation - a basic knowledge you can apply during the period of cultural study and in future algorithm programs.
- 9 extension Visual Studio Code for easier programmingmicrosoft visual studio code is one of the best free code editors today. it is full of features, easy to use and good performance.
- 10 reasons to use Godot Engine for game developmentnow it is easier than ever to develop a game thanks to many free game development tools and online tutorials, anyone can create a simple game.