-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_set.py
More file actions
39 lines (30 loc) · 889 Bytes
/
09_set.py
File metadata and controls
39 lines (30 loc) · 889 Bytes
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
#Set
#A set is a collection which is unordered, unchangeable,
# unindexed, do not allow duplicate values and
# True and 1 are considered the same value in sets, and are treated as duplicates
#Create set
first_set = {'Banana', 'Apple', 'Cherry', 'Apple', True, False, 1, 0}
print(first_set) #Output {'Banana', 'Apple', 'Cherry'} Not allow duplicate values
#Set length
print(len(first_set))
#Add new value in the set
first_set.add("Strawberry")
print(first_set)
#Remove a value from a set
first_set.remove('Banana')
print(first_set)
#A set can contain different data types:
second_set = {"abc", 34, True, 40, "male"}
print(second_set)
#check the type
print(type(second_set))
#Union set's
set1 = {1,2,3,4}
set2 = {5,6,7,8}
set3 = {9,10,11,12}
#First possible to union set's
set4 = set1.union(set2, set3)
print(set4)
#Second option to union set's
set5 = set1 | set2 | set3
print(set5)