-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathday11.py
More file actions
55 lines (31 loc) · 1.13 KB
/
day11.py
File metadata and controls
55 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""In Python, a set is a built-in data type that represents an unordered collection of unique elements. Sets are commonly used for tasks that involve checking for membership, eliminating duplicates, and performing set operations like union, intersection, and difference. You can create a set in Python using curly braces {} or by using the set() constructor"""
# Creating a set
# my_set = {1, 2, 3, 4, 5}
# print(my_set[0]) not allowed
# print(my_set)
# my_set = {1, 2, 3, 4, 5,5,6}
# print(my_set) duplicate value not allowed
# Adding elements to a set
# my_set.add(7)
# print(my_set)
# Removing elements from a set
# my_set.remove(3) # Raises an error if the element is not found
# print(my_set)
# my_set.discard(7)
# print(my_set)
# loop through set
# for i in my_set:
# print(i)
# Set methods
# print(len(my_set))
# # union method
# my_set1 = {1, 2, 3, 4, 5,5,6}
# my_set2={7,8,9,10}
# new_set=my_set1.union(my_set2)
# print(new_set)
# intersection
# # union method
# my_set1 = {1, 2, 3, 4,6}
# my_set2={7,8,4,6}
# new_set=my_set1.intersection(my_set2)
# print(new_set)