Pratical 8
Pratical 8
Pratical 8
Roll no :- 23
Practical 8
# initialize a with {}
a = {}
# check data type of a
print(type(a))
# initialize a with set()
a = set()
# check data type of a
print(type(a))
# Different types of sets in Python set of integers
my_set = {1, 2, 3}
print(my_set)
# set of mixed datatypes
my_set = {1.0, "Hello", (1, 2, 3)}
print(my_set)
# Different types of sets in Python set of integers
my_set = {1, 2, 3}
print(my_set)
# pop an element
# Output: random element
print(my_set.pop())
# pop another element
my_set.pop()
print(my_set)
# clear my_set
# Output: set()
my_set.clear()
print(my_set)
print(my_set)
XI)
1) set1 = set([0, 1, 2, 3, 4, 5])
print("new element added in the set")
set1.add(23)
print(set1)
print("Element deleted from the set")
set1.discard(4)
print(set1)
2) E = {0, 2, 4, 6, 8};
N = {1, 2, 3, 4, 5};
# set union
print("Union of E and N is:",E | N)
# set intersection
print("Intersection of E and N is:",E & N)
# set difference
print("Difference of E and N is:",E - N)
# set symmetric difference
print("Symmetric difference of E and N is:",E ^ N)
E.clear()
print("remove all elements of E set:",E)
3) s1= {10, 24, 47, 62, 78};
print("maximum value=",max(s1))
print("minimum value=",min(s1))
4) s1= {10, 24, 47, 62, 78};
print("length=",len(s1))