The set() function creates a set in Python.
Example
list_numbers = [1, 2, 3, 4, 2, 5]
# create set from list
numbers_set = set(list_numbers)
print(numbers_set)
# Output: {1, 2, 3, 4, 5}
set() Syntax
The syntax of set() is:
set(iterable)
Also Read: Python sets
set() Parameters
set() takes a single optional parameter:
- iterable (optional) - a sequence (string, tuple, etc.) or collection (set, dictionary, etc.) or an iterator object to be converted into a set.
set() Return Value
set() returns:
- an empty set if no parameters are passed
- a set constructed from the given iterable parameter