Google News
logo
Python Program to Using the set() constructor to create a set
In the following example of Python program to demonstrate how to create a set using the `set()` constructor :
Program :
# create a set using the set() constructor
my_set = set([1, 2, 3, 4, 5])

# print the set
print(my_set)


In this example, we create a set called `my_set` using the `set()` constructor. We pass in a list of integers `[1, 2, 3, 4, 5]` as an argument to the `set()` constructor to create the set.

Then, we simply print the set using the `print()` function.

Output :
{1, 2, 3, 4, 5}
Note that sets are unordered collections of unique elements, so the order in which the elements are printed may differ from the order in which they were added to the set.