English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
O método Frozenset() retorna um objeto frozenset imutável, inicializado pelos elementos do iterable fornecido.
O conjunto congelado é apenasPython setversão imutável do objeto. Embora os elementos do conjunto possam ser modificados a qualquer momento, os elementos do conjunto congelado permanecem inalterados após a criação.
Portanto, o conjunto congelado pode ser usado comono DictionaryUm conjunto ou usado como elemento de outro conjunto. No entanto, como um conjunto, ele também não é ordenado (pode definir elementos em qualquer índice).
The syntax of the Frozenset() method is:
frozenset([iterable])
The Frozenset() method can optionally use a single parameter:
iterable (optional) -iterable, it contains elements for initializing Frozenset.
Can set Iterable, Dictionary,Tupleetc.
The Frozenset() method returns an immutable Frozenset (frozen set) that initializes with the elements of the given iterable.
If no parameters are passed, it returns an empty Frozenset.
# Tuple vowels vowels = ('a', 'e', 'i', 'o', 'u') fSet = frozenset(vowels) print('The frozen set is:', fSet) print('The empty frozen set is:', frozenset())
When running the program, the output is:
The frozen set is: frozenset({'o', 'i', 'e', 'u', 'a'}) An empty frozen set is: frozenset()
When you use a dictionary as an iterable for a frozenset. You only need the keys of the dictionary to create a set.
# Random dictionary person = {'name': 'John', 'age': 23, 'sex': 'male'} fSet = frozenset(person) print('The frozen set is:', fSet)
When running the program, the output is:
The frozen set is: frozenset({'name', 'sex', 'age'})
Like a regular set, frozenset can also perform different operations, such as union, intersection, etc.