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:
Python Errors and Built-in Exceptions
Python chr()
Python String partition()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python any()
Python Program to Display Powers of 2 Using Anonymous Function
Python Data Types
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python String islower()
Python Iterators
Intelligent Projects Using Python - Santanu Pattanayak
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Differentiate Between type() and isinstance()
Python Dictionary values()
Python Program to Differentiate Between del, remove, and pop on a List
Python Set intersection()
Python String find()
Python isinstance()
Python List remove()
Python __import__()
Python Program to Find the Size (Resolution) of a Image
Python Objects and Classes
Python List index()
Python frozenset()
Python exec()
Python Program to Calculate the Area of a Triangle
Python Numbers, Type Conversion and Mathematics
Converting Between a List and a Set in Java
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Node.js vs Python for Backend Development
Python Program to Print the Fibonacci sequence
Java Program to Implement Dijkstra’s Algorithm using Set