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()
print(x)
#Create a non empty set
n = set([0, 1, 2, 3, 4])
print(n)
Sample Output:
set() {0, 1, 2, 3, 4}
Pictorial Presentation:
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 iterate over sets.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Converts a number to a list of digits
Example:
def tips_digit(n): return list(map(int, str(n))) print(tips_digit(2468))
Output:
[2, 4, 6, 8]
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework