You are on page 1of 3

Name: Rais Saaim Ravish Enrollment No: 2105690153 Batch: 2

1.Write a Python program to create a set, add member(s) in a set


and remove one item from set.
s={10,20,30,40,50}
print(s)
s.add(60)
print(s)
s.pop()
print(s)

OUTPUT :
{50, 20, 40, 10, 30}
{50, 20, 40, 10, 60, 30}
{20, 40, 10, 60, 30}

2. Write a Python program to perform following operations on set:


intersection of sets, union of sets, set difference, symmetric difference,
clear a set.
#set operation
s={10,20,30,40,50}
s2={60,70,10,20,50,30,80,90}
#union
s3=s.union(s2)
print(s3)
#intersection
s4=s.intersection(s2)
print(s4)
#difference
s5=s.difference(s2)
print(s5)
#symmetric_difference
s6=s.symmetric_difference(s2)
print(s6)
#clear
s7={20,30,60,40,59}
s7.clear()
print(s7)
#union
s8=s | s2
print(s8)
#intersection
s9=s & s2
print(s9)
#difference
s10=s - s2
print(s10)

OUTPUT :
{70, 40, 10, 80, 50, 20, 90, 60, 30}
{50, 10, 20, 30}
{40}
{70, 40, 80, 90, 60}
set()
{70, 40, 10, 80, 50, 20, 90, 60, 30}
{50, 10, 20, 30}
{40}

3. Write a Python program to find maximum and the minimum value in


a set.
s={10,20,30,40,50}
print(max(s))
print(min(s))
OUTPUT :
50
10

4. Write a Python program to find the length of a set.


s={10,20,30,40,50}
print(len(s))

OUTPUT :
5

You might also like