-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsets.py
More file actions
46 lines (29 loc) · 898 Bytes
/
sets.py
File metadata and controls
46 lines (29 loc) · 898 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
40
41
42
43
44
45
46
#/bin/python
""" this program depicts the use of sets in python """
# sets are unordered and unindexed they are written using curly braces {}
# we cannot change items but we can add items and remove items
myset = {"maths","physics","chemistry","Computer Science"}
print(myset) # set is printed in opposite fashion
for x in myset:
print(x)
print("banana" in myset)
print("maths" in myset)
myset.add("Subjects")
print(myset)
# adding multiple items using update method
myset.update(["update","multiple","items"])
print(myset)
print(len(myset))
myset.remove("update") # remove takes exactly one argument
print(myset)
myset.clear()
print(myset)
""" joining two sets """
set1 = {"Facebook","Apple","Amazon"}
set2 = {"Netflix","Google"}
print("set1 is ",set1,"set2 is ",set2)
set3 = set1.union(set2)
print(set3)
# set constructor
thisisset = set(("new","set"))
print(thisisset)