Python‎ > ‎set‎ > ‎

set.clear()

http://www.adilwaseem.com/

Definition
Remove all elements from this set.

Syntax
set.clear(x)

Parameters
x=set items

Example
The output is:
 set1={3,45,344,66}
set1.clear()
print(set1)
>>> 
set()
>>>

String set
The method clear the set string value.
 >>> set1={"Python", "Research", "Centre"}
>>> set1.clear()
>>> set1
set()
>>>

del(set)
The function delete the set but the set.clear() only delete the item while the set remain in the Python memory.
 >>> set1={3,45,344,66}
>>> del(set1)
>>> set1
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
set1
NameError: name 'set1' is not defined
>>>

set.clear()
The method clear the set items.
 >>> from decimal import Decimal
>>> a=set()
>>> a.add(Decimal(1).adjusted())
>>> a.add(Decimal(.55).canonical())
>>> a.add(Decimal(-1).compare_signal(1))
>>> a
{0, Decimal('0.5500000000000000444089209850062616169452667236328125'), Decimal('-1')}
>>> b=set()
>>> b.add(Decimal(1).compare_total(2))
>>> b.add(Decimal(0.1).copy_abs())
>>> b
{Decimal('0.1000000000000000055511151231257827021181583404541015625'), Decimal('-1')}

>>> a={0, Decimal('0.5500000000000000444089209850062616169452667236328125'), Decimal('-1')}
>>> a.copy()
{Decimal('0.5500000000000000444089209850062616169452667236328125'), 0, Decimal('-1')}
>>> a.clear()
>>> a
set()

Comments