Header Ads

Sets in python



Set is one type of unordered list , It is any type of collection. you can add number of elements inside list inside "{}" bracket.

To create set We represent set in starting with { bracket and end with } bracket For Example,


Set_1 = {"hello", "Rohit","Rock"}


Suppose you have example of set_2

set_2 = {"jockey","hola","hola","9965",552}

Note that 9965 written inside [" "] bracket , It acts as string not integer number. in this case, 'hola' appear two times. 
You have to remove this string and write only one string. so we put set inside set.

What do you mean 'set inside set ? '

set() is a function that written inside a set to remove repeated number of set. following example will give more understanding of set() function.


Operation in set:

Let say you want to add one element inside previous set then write following command,
set_name.add("element")



same as remove element from set,
set_name.remove("Element")












No comments

Powered by Blogger.