Function Details: set

Description


Returns a new set object, optionally with elements taken from iterable.


Extended Description


The set() function creates a new set object. Sets are unordered collections with no duplicate elements. They support mathematical operations like union, intersection, difference, and symmetric difference. Sets are mutable, and elements must be immutable (hashable). If an iterable is provided, it creates a set with elements from the iterable.


Read More about set from Python Documentation

Function Signature


set(iterable: Optional[Iterable] = None) -> set

Module: builtins

Class: set

Parameters



Parameter List


  • iterable: Optional[Iterable]

Return


Returns a new set object.


Return Type


set

Output

Explanation

These examples show how to create sets from different types of iterables and how duplicates are automatically removed.