Built-in Functions and Types
set()
Collect distinct hashable elements into a mutable set. Equal values collapse into one entry, even if their types differ (for example 1 and True). Sets have no guaranteed positional order and cannot be indexed. The empty literal {} creates a dict, not a set. Set objects themselves are unhashable.
Formal Syntax & Structure
python syntaxpython
set(iterable=(), /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| iterable | iterable of hashable objects | Input elements; omitted input produces an empty set. |
Return Value
set
Mutable unordered collection of distinct elements.
Working Example
Example Snippetpython
tags = set(["red", "blue", "red"])print(sorted(tags))print("blue" in tags)