[go: up one dir, main page]

0% found this document useful (0 votes)
15 views2 pages

Practical 08 Py

The document contains Python programs demonstrating various set operations, including creating a set, adding and removing items, performing intersections, unions, differences, and symmetric differences of sets, as well as clearing a set. It also includes programs to find the maximum and minimum values in a set and to determine the length of a set. Each operation is illustrated with example code and print statements to display the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Practical 08 Py

The document contains Python programs demonstrating various set operations, including creating a set, adding and removing items, performing intersections, unions, differences, and symmetric differences of sets, as well as clearing a set. It also includes programs to find the maximum and minimum values in a set and to determine the length of a set. Each operation is illustrated with example code and print statements to display the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL 08

1.Write a python program to create a set ,add members in a set and remove one 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)#a.discard(3)
print("Removing 1 in set a\n",a)

2.Write a python program to perform the following operations on set: the intersection 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 set",s1&s2)
print("Union of set",s1|s2)
print("Difference of seta s1=",s1-s2)
print("Symmetric difference =",s1^s2)
s1.clear()
print("S1 is cleared=",s1)
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))

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))

You might also like