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:
Convert a Map to an Array, List or Set in Java
Python Strings
Python map()
Python List extend()
Python hex()
Python Tuple
Python Dictionary get()
Python Program to Find the Factors of a Number
Python Set intersection()
Python Data Types
Python Global, Local and Nonlocal variables
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Deep Learning in Python - LazyProgrammer
Python Generators
Python Program to Convert Bytes to a String
Python Program to Print Hello world!
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Reverse a Number
Python List
Python vars()
Python if...else Statement
Python Program to Display Calendar
Python Type Conversion and Type Casting
Python String isprintable()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Create a Long Multiline String
Python Program to Print Output Without a Newline
Python List insert()
Python String lstrip()
Python String format()
Python dir()