0% found this document useful (0 votes)
27 views2 pages

Class 10 Set Frozenset

Uploaded by

kunala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Class 10 Set Frozenset

Uploaded by

kunala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

set Data type:-

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 {}.

1,Insrtion order is not presserved.


2,duplicates are not allowed.
3,hetrogenous objects are allowed.
4,Indexing concept is not applicable
5,It is mutable.
6,Growable in nature.

ex:-
>>> s = {100,0,10.78,True,'scodeen'}
>>> type(s)
<class 'set'>

Methods of set:-

'add', 'clear', 'copy', 'difference', 'difference_update', 'discard',


'intersection', 'intersection_update', 'isdisjoint', 'issubset', 'issuperset',
'pop', 'remove', 'symmetric_difference', 'symmetric_difference_update', 'union',
'update'

1.add :- Add an element to the set.


ex:-
>>> set = {'apple','bananna','cherry'}
>>> set.add('orange')
>>> set
{'apple', 'cherry', 'bananna', 'orange'}

2.clear:-Remove all the element from the corresponding set.


ex:-
>>> set = {'apple','bananna','cherry'}
>>> set.clear()
>>> set
set()

3.copy:- Retuens the copy of the set.


ex:-
>>> set = {'apple','bananna','cherry'}
>>> t = set.copy()
>>> t
{'apple', 'cherry', 'bananna'}

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'}

6.intersection:- Returns a set ,that is the intersection of two or more sets.

ex:
>> x ={'apple','bananna','cherry'}
>>> y = {'google','microsoft','apple'}
>>> z= x.intersection(y)
>>> z
{'apple'}

7.pop:-Removes an element from the set.


ex:-
>>> x ={'apple','bananna','cherry'}
>>> x.pop()
'apple'
>>>

8.remove:- Removed specified element.


ex:-
>>> x ={'apple','bananna','cherry'}
>>> x.remove('cherry')
>>> x
{'apple', 'bananna'}

9.union:- Return a set conataining the union of set.


ex:-
>>> x ={'apple','bananna','cherry'}
>>> y = {'google','microsoft','apple'}
>>> z = x.union(y)
>>> z
{'apple', 'cherry', 'google', 'bananna', 'microsoft'}
>>>

Frozenset:-

It is exact same as set but fozenset is immutable.


Hence we cannot use add or rempove function.

ex:-
>>> s = {10,20,30}
>>> fs = frozenset(s)
>>> type(fs)
<class 'frozenset'>

You might also like