Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Set is a collection of unique data and it is used to display value randomly.set is also called a collection of finite elements.


The set will be declared by {} to store different types of data.

var = {value1,value2,value3,...}


arr = {1,2,3,5,7,7,8,9}
print(arr)
for j in arr:
    print(j)


Predefine method for set:-

1 add():-  using this we can add element dynamically in set.

arr.add(45)

2 intersect():- it provide common element in set

a = {1,2,3,4,5}
b= {1,2,3}
c= a.intersect(b)
print(c)



The pre-define method in Python Set:-

arr = {1,2,3,5,7,7,8,9}

for j in arr:
    print(j)

arr.add(55)
print(arr)
a = {1,2,3,4,5}
b= {1,2,3,7}
c= a.intersection(b)
print(c)
d = a.union(b)
print(d)
d1 = a.difference(b)
print(d1)
a.remove(2);
print(a)
d2 = a.clear()
print(d2)




WAP to count total integer, float, string element in set?

WAP to display set elements in sorted order without using the predefined method?

WAP display factorial of all prime elements in the set?






Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post