clear() method for set
« All set methods
clear() takes no argument.
Returns : No return value.
my_set={'a','b','c','d','e'}
my_set.clear()
print(my_set)
Output is here
set()
del and clear() difference
We can use keyword del to remove any object. Once it is removed then further use of it raise NameError.
my_set={'a','b','c','d','e'}
del my_set
print(my_set)
Here we will removed the set object by using del, so the last line will generate the error ( NameError)
« All set methods « Questions with solutions on set discard()
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com