This set()
function returns a set object i.e. it creates a set.
set([iterable])
Here,
Note: You cannot create empty sets using {}
syntax as it creates an empty dictionary. To create an empty set, you need to use set()
.
>>> # with string
>>> set('Cloudyfox')
{'o', 'x', 'f', 'y', 'u', 'C', 'd', 'l'}
>>> # with tuple
>>> set(('a', 'e', 'i', 'o', 'u'))
{'i', 'o', 'a', 'u', 'e'}
>>> # with list
>>> set(['a', 'e', 'i', 'o', 'u'])
{'i', 'o', 'a', 'u', 'e'}
>>> # with range
>>> set(range(10))
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
# With another set
>>> set({'o', 'x', 'f', 'y', 'u', 'C', 'd', 'l'})
{'o', 'x', 'f', 'y', 'u', 'C', 'd', 'l'}
>>> # with dictionary
>>> set({'a':1, 'b': 2, 'c':3, 'd':4})
{'c', 'a', 'd', 'b'}
>>> # with frozenset
>>> set(frozenset(('a', 'e', 'i', 'o', 'u')))
{'i', 'o', 'e', 'a', 'u'}