Python Exercise: Create a new empty set

Python sets: Exercise-1 with Solution

Write a Python program to create a new empty set.

Sample Solution:-

Python Code:

#Create a new empty set 
x = set()
#Create a non empty set
n = set([0, 1, 2, 3, 4])

Sample Output:

{0, 1, 2, 3, 4}  

Pictorial Presentation:

NumPy Sets: Create a new empty set.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Python Sets Exercise Home.
Next: Write a Python program to iteration over sets.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Python: How do I concatenate two lists in Python?

You can use the + operator to combine them:

listone = [1,2,3]
listtwo = [4,5,6]

joinedlist = listone + listtwo


>>> joinedlist

Ref: https://bit.ly/2B8fL40