Python set Data Type (PYTHON FUNDAMENTALS)

Created with Sketch.

Python set Data Type:

If we want to represent a group of values without duplicates where the order is not
important then we should go for set Data Type.
1) Insertion order is not preserved
2) Duplicates are not allowed
3) Heterogeneous objects are allowed
4) Index concept is not applicable
5) It is a mutable collection
6) Growable in nature

Eg:

 s={100,0,10,200,10,'mohan'} 
 s # {0, 100, 'mohan', 200, 10} 
 s[0] ---> TypeError: 'set' object does not support indexing 

set is growable in nature, based on our requirements we can increase or decrease the
size.

>>> s.add(60) 
>>> s 
{0, 100, 'mohan', 200, 10, 60} 
>>> s.remove(100) 
>>> s 
{0, 'mohan', 200, 10, 60} 

Leave a Reply

Your email address will not be published. Required fields are marked *