English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
El método Frozenset() devuelve un objeto frozenset inmutable, inicializado con los elementos del iterable dado.
El conjunto congelado es soloPython setversión inmutable de un objeto. Aunque se puede modificar en cualquier momento los elementos del conjunto, los elementos del conjunto congelado se mantienen inmutables después de su creación.
Por lo tanto, el conjunto congelado se puede utilizar comoEn el diccionario deUna clave o un elemento utilizado como otro conjunto. Sin embargo, al igual que un conjunto, no es ordenado (se puede establecer un elemento en cualquier í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 used to initialize Frozenset.
Can set Iterable, Dictionary,Tupleetc.
The Frozenset() method returns an immutable Frozenset (frozen set) initialized with elements from 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 object for 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.