Practical 8
1.Write a python program to create a set ,add members in a set and removeone item from
set.
a={1,2,3,4,5}
print("set=",a)
a.add(6)
print("Adding 6 in set a¥n",a)
a.remove(1)
print("Removing 1 in set a¥n",a)
output:
2.Write a python program to perform the following operations on set: theintersection of sets,
the union of sets, set difference, symmetric difference,clear a set.
s1={1,2,3,4,5,6,7}
s2={5,6,7,8,9,10}
print("s1 =", s1)
print("s2 =", s2)
print("intersections of sets",s1 & s2)
print("Union of sets",s1 | s2)
print("Difference of sets (s1-s2)=",s1-s2)
print("Symmetric difference =",s1^s2)
s1.clear()
print("S1 is cleared=",s1)
output:
3.Write a python program to find maximum and minimum value in a set.
s1={1,2,3,4,5}
print("set=",s1)
print("Maximum value=",max(s1))
print("Minimum value=",min(s1))
output:
4.Write a python program to find length of a set.
set={0,1,2,3,4,5}
print("set=",set)
print("length=",len(set))
output: