Python Practice › Set Programs › Program 23
Clear a set
Write a Python program to remove all elements from a set.
Input
{1, 2, 3}Output
set()
Approach
clear().
Solution
s = {1, 2, 3}s.clear()print(s)Output
set()
Learn the concept
New to this topic? Read the lesson, then come back.