Explanation:
1. Creating a Frozenset
x = frozenset([1, 2, 2, 3])
- frozenset() creates an immutable set.
- It automatically removes duplicate elements.
- The value of x becomes {1, 2, 3}.
- Unlike a normal set, a frozenset cannot be modified after creation.
2. Performing Set Union
x | {3, 4, 5}
- The | operator performs a union operation.
- It combines elements from both sets.
- Duplicate elements are automatically removed.
- Result: {1, 2, 3, 4, 5}.
3. Counting Unique Elements
len(x | {3, 4, 5})
- len() counts the total number of elements.
- The union contains 5 unique elements.
- Therefore, the output is 5.
Output
5
.png)

0 Comments:
Post a Comment