Table of Contents
The clear() method removes all elements from the set.
The syntax of clear()
method is:
set.clear()
1. Set clear() Parameters
clear()
method doesn’t take any parameters.
2. Return value from Set clear()
clear()
method doesn’t return any value and returns a None
.
3. Example 1: Remove all elements from a Python set using clear()
# set of vowels vowels = {'a', 'e', 'i', 'o', 'u'} print('Vowels (before clear):', vowels) # clearing vowels vowels.clear() print('Vowels (after clear):', vowels)
Output
Vowels (before clear): {'e', 'a', 'o', 'u', 'i'} Vowels (after clear): set()
Related posts:
Converting Between a List and a Set in Java
Python Get Current time
Python Program to Print the Fibonacci sequence
Python Statement, Indentation and Comments
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Input, Output and Import
Python print()
Python Set intersection()
Convert a Map to an Array, List or Set in Java
Python String zfill()
Python sleep()
Python Machine Learning - Sebastian Raschka
Python min()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Shuffle Deck of Cards
Python Program to Check If a String Is a Number (Float)
Python Program to Get Line Count of a File
Python Package
Python String isdigit()
Python frozenset()
Python Program to Append to a File
Python Program to Extract Extension From the File Name
Python Generators
Python Program to Randomly Select an Element From the List
Python __import__()
Python Keywords and Identifiers
Python Program to Count the Occurrence of an Item in a List
Python bin()
Python iter()
Python Program to Swap Two Variables
Python Program to Capitalize the First Character of a String
Python callable()