Class 10 Set Frozenset
Class 10 Set Frozenset
if we want to represent a group of values without duplicate and where order is not
imp.Then we should for set datatype and this datatype will eclosed with curly
bracket {}.
ex:-
>>> s = {100,0,10.78,True,'scodeen'}
>>> type(s)
<class 'set'>
Methods of set:-
4.difference:- returns a set that contains the items that only exits in set x,and
not in set y.
ex:-
>>> x ={'apple','bananna','cherry'}
>>> y = {'google','microsoft','apple'}
>>> z= x.difference(y)
>>> z
{'cherry', 'bananna'}
>>> a = y.difference(x)
>>> a
{'google', 'microsoft'}
>>>
5.discard:- Remove the specified item.
ex:-
>>> set = {'apple','bananna','cherry'}
>>> set.discard('apple')
>>> set
{'cherry', 'bananna'}
ex:
>> x ={'apple','bananna','cherry'}
>>> y = {'google','microsoft','apple'}
>>> z= x.intersection(y)
>>> z
{'apple'}
Frozenset:-
ex:-
>>> s = {10,20,30}
>>> fs = frozenset(s)
>>> type(fs)
<class 'frozenset'>