What are the functions of the set() function in Python?
The set() function in Python has the following functionality:
- Create an empty set: set()
- Convert an iterable object into a collection: set(iterable)
- Remove duplicate elements from an iterable object and return a new set: set([iterable])
- Add an element to the collection: set.add(element)
- Remove an element from the set: set.remove(element)
- length
- includes
- Find the intersection of two sets by using the function set.intersection(other_set).
- Find the union of two sets: set.union(other_set)
- Find the difference between two sets: set.difference(other_set)
- Check if a set is a subset of another set: set.issubset(other_set)
- Determine if one set is a superset of another set: set.issuperset(other_set)
- Check if two sets have any overlap: set.isdisjoint(other_set)
- Empty all elements in the set: set.clear()