Social Media

1/04/2019

Set Introduction

Set is a data structure in Python which is denoted by {}.
Duplicate values are not allowed in set.
We cannot use indexing and slicing here.
It is mutable data structure.

Creation of empty set:
s=set()
print(type(s)) # set
Note* s={} is not empty set. It is dictionary.

Set does not preserve any sequence of storing data elements.
s=set("mayank")
print(s) # {'n', 'm', 'a', 'y', 'k'}

Set can only take sequence as argument.
s=set([1,2,2,3,4]) # 2 will store only once as repetition is not allowed here. 
print(s) # {2,1,4,3}






Be First to Post Comment !
Post a Comment