Javatpoint Logo
Javatpoint Logo

Python set() Function

In python, a set is a built-in class, and this function is a constructor of this class. It is used to create a new set using elements passed during the call. It takes iterable as an argument and returns a new set object. The constructor syntax is given below.



iterable: a collection of immutable elements.


It returns a new set.

Let's see some examples of set() function to understand it's functionality.

Python set() Function Example 1

A simple example to create a set of using iterable elements.


{'1', '2'}
{'a', 'n', 'v', 't', 'j', 'p', 'i', 'o'}

Python set() Function Example 2


{'15', '13', '12'}
{'n', 'v', 'a', 'j', 'p', 't', 'o', 'i'}
{1, 2, 3}

Python set() Function Example 3

Here, we are creating a set of filtered elements. The geteven function returns even values.


{8, 2, 4, 6}

Next TopicPython Functions

Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials

B.Tech / MCA