Python: set() function
set() function
The set() function is used to create a set object.
Read more about set from Python Set and Python Exercises.
Version:
(Python 3.2.5)
Syntax:
set([iterable])
Parameter:
Name | Description | Required / Optional |
---|---|---|
iterable | A sequence. | Optional |
Return value:
An empty set without any parameters.
A set constructed from the given iterable parameter.
Example: Python set() function
# empty set
print(set())
# from string
print(set('Python'))
# from tuple
print(set(('e', 'x', 'e', 'r', 'c', 'i','s','e')))
# from list
print(set(['a', 'e', 'i', 'o', 'u']))
# from range
print(set(range(7)))
Output:
set() {'h', 'y', 'n', 't', 'o', 'P'} {'s', 'i', 'r', 'c', 'e', 'x'} {'i', 'o', 'a', 'e', 'u'} {0, 1, 2, 3, 4, 5, 6}
Pictorial Presentation:
Pictorial Presentation:
Python Code Editor:
Previous: round()
Next: setattr()
Test your Python skills with w3resource's quiz
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python/built-in-function/set.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics