# homo and hetero# True is 1 (duplicate values are ignored)# Tuples are immutable, so they can be contained in a sets3={1,'hello',3+4j,(4,5,6),True}print(s3)
Sets are mutable (you can add/remove items), but the individual items within a set are immutable. You cannot change an item at a specific position, resulting in a TypeError.
# unions1={1,2,3}s2={3,4,5}print('\nUnion of the set is :',s1|s2)print('Union of the set is :',s1.union(s2))# intersectionprint('\nIntersection of the set is :',s1&s2)print('Intersection of the set is :',s1.intersection(s2))# differenceprint('\nDifference of the set is :',s1-s2)print('Difference of the set is :',s1.difference(s2))# symmetric differenceprint('\nSymmetric difference of the set is :',s1^s2)print('Symmetric difference of the set is :',s1.symmetric_difference(s2))
s={1,2,3}print(" lenght of the function :",len(s))print(" max of the function :",max(s))print(" min of the function :",min(s))print(" sorted of the function :",sorted(s))
# isdisjoint/ issubjoint /issupjoints1={1,2,3}s2={3,4,5}s3={1,2,3,5,6,7}print(" Disjoint set is :",s1.isdisjoint(s2))print(" Subjoint set is :",s1.issubset(s2))print(" Supjoint set is :",s3.issuperset(s1))
Frozensets are immutable versions of Python sets. Like tuples for lists, frozensets can be nested inside other sets (or used as dictionary keys) because they are hashable. All read-only set functions work, but all methods that modify the set (write functions like .add(), .remove(), etc.) will not work.
A frozenset is created using the built-in frozenset() constructor, usually passed an iterable (like a list or a regular set).
Frozensets support all set theory operations (union, intersection, difference, etc.) using both operators and methods, which return a new frozenset as a result.