Skip to content

Python Set clear() | Method

  • by

Python Set clear() Method is used to remove all items from the set. All elements from the set will clear. And we will leave with an empty set.


This method doesn’t take any parameters and doesn’t return any value.

Set clear in Python

Simple example code.

sno = {2, 3, 5, 7}

# clear all elements



Python Set clear() Method

clear() Method with a String Set

# set of strings
names = {'John', 'Walter', 'Pink'}
print('Strings (before clear):', names)

# clear strings
print('Strings (after clear):', names)

Do comment if you have any doubts or suggestions on this Python set method topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.