Create Sets In Python

aimtocode

Python Set Definition

A set is an unordered collection data type with no duplicate elements. Sets are iterable and mutable. The elements appear in an arbitrary order when sets are iterated.

The elements of the set can not be duplicate. The elements of the python set must be immutable.

Creating a Set

Sets can be created by calling the built-in set() function with a sequence or another iterable object.

A set can be created also by using the curly braces as well.


Example 1: using set() method



Output:

 Printing the element using for loop...
 Pankaj
 Sujeet
 Rahul
 Amol
 Prayag
 Rakesh
 Mukesh

Example 2: using curly praces




Output:

 Printing the element using for loop...
 Sujeet
 Rakesh
 Mukesh
 Amol
 Rahul
 Prayag
 Pankaj


aimtocode