# Getting exclusive elements of a set in Julia – setdiff() and setdiff!() Methods

• Last Updated : 24 Feb, 2021

The setdiff() is an inbuilt function in julia which is used to returns the elements which are in first set but not in second set.

Syntax:

`setdiff(s, itrs...)`

Parameters:

• s: Specified first set.
• itrs: Specified second set.

Returns: It returns the elements which are in first set but not in second set.

Example:

## Python

 `# Julia program to illustrate``# the use of setdiff() method`` ` `# Getting the elements which are``# in first set but not in second set.``println(setdiff([``1``, ``4``, ``6``], [``1``, ``3``, ``5``]))``println(setdiff([``1``, ``2``, ``3``, ``4``], [``0``, ``1``, ``2``, ``3``]))``println(setdiff(``Set``([``2``, ``3``]), BitSet([``3``, ``4``])))`

Output:

#### setdiff!()

The setdiff!() is an inbuilt function in julia which is used to remove each element of set s which are also in the specified iterable.

Syntax:

`setdiff !(s, itrs...)`

Parameters:

• s: Specified first set.
• itrs: Specified iterable.

Returns: It returns the remaining elements of the set s after removal.

Example:

## Python

 `# Julia program to illustrate``# the use of setdiff!() method`` ` `# Getting the remaining elements of``# the set s after removal.``A ``=` `Set``([``1``, ``2``, ``3``, ``4``]);``setdiff !(A, ``1``:``2``:``3``);``println(A)` `B ``=` `Set``([``1``, ``2``, ``3``, ``4``, ``5``, ``6``]);``setdiff !(B, ``1``:``3``:``5``);``println(B)`

Output:

```Set([4, 2])
Set([2, 3, 5, 6])```

My Personal Notes arrow_drop_up