Python set() Function
Description
set() The function creates an unordered set of unique elements, which can be used for relationship testing, removing duplicates, and computing intersections, differences, unions, etc.
Syntax
set syntax:
class set([iterable])
Parameter Description:
- iterable -- an iterable object;
Return Value
Returns a new set object.
Example
The following examples demonstrate how to use set:
x
=
set
(
'
runoob
'
)
y
=
set
(
'
'
)
x
,
y
(
set
(
[
'
b
'
,
'
r
'
,
'
u
'
,
'
o
'
,
'
n
'
]
)
,
set
(
[
'
e
'
,
'
o
'
,
'
g
'
,
'
l
'
]
)
)
Duplicates are removed
x
&
y
Intersection
set
(
[
'
o
'
]
)
x
|
y
Union
set
(
[
'
b
'
,
'
e
'
,
'
g
'
,
'
l
'
,
'
o
'
,
'
n
'
,
'
r
'
,
'
u
'
]
)
x
y
Difference
set
(
[
'
r
'
,
'
b
'
,
'
u
'
,
'
n
'
]
)
Python built-in function