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 String zfill()
Python Program to Convert Celsius To Fahrenheit
Python String isspace()
Python String ljust()
Python List copy()
Python Global, Local and Nonlocal variables
Python Program to Solve Quadratic Equation
Python __import__()
Python Program to Find the Largest Among Three Numbers
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python all()
Python Namespace and Scope
Python String partition()
Python Input, Output and Import
Python Operator Overloading
Python String maketrans()
Python Operators
Python chr()
Python Program to Check if a Number is Odd or Even
Python List count()
Python Program to Check Leap Year
Python Program to Print Hello world!
Python str()
Python Program to Check the File Size
Python String endswith()
Python Program to Display Fibonacci Sequence Using Recursion
Python Package
Python Set difference()
Python Set isdisjoint()
Python type()
Python Tuple index()
Deep Learning with Python - Francois Chollet