Create Empty Set in Python

Create Empty Set

To create an empty set in Python, call set() builtin function. set() function with no arguments passed creates and returns an empty set.

Example

In the following program, we create an empty set using set() builtin function. We assign the empty set to a variable mySet.

Python Program

mySet = set()
Run

Now, let us add some elements to the set, and print the set.

Python Program

mySet = set()
mySet.add('apple')
mySet.add('banana')
mySet.add('banana')
print(mySet)
Run

Output

{'apple', 'banana'}

Summary

In this tutorial of Python Examples, we learned how to use set() method to create an empty Set in Python, with the help of well detailed example programs.