set
Create a set from the items of an iterable.
Python 3.13
set([iterable])- [ ]optional part
- iterable
- The items of the new set; without it, an empty set is created.IterableOptional
Return value
A new set without duplicates; the order of items is not kept.
Examples
Set without duplicates
Python 3.13
print(set([1, 2, 2, 3])){1, 2, 3}Number of distinct characters
Python 3.13
print(len(set('mississippi')))4
Details
An empty set can only be created with set(): {} creates an empty dictionary. Items must be hashable, so lists cannot be put into a set.
