-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8. Q3.py
More file actions
22 lines (18 loc) · 794 Bytes
/
8. Q3.py
File metadata and controls
22 lines (18 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Create an empty set. Write a program that adds five
#new names to this set, modifies one existing name and
#deletes two names from it.
# Create an empty set
name_set = set()
# Add five new names
name_set.update(['Alice', 'Bob', 'Charlie', 'David', 'Eva'])
print("After adding 5 names:", name_set)
# Modify one name: Let's change 'Charlie' to 'Chris'
# (Since sets don't support direct modification, remove and re-add)
if 'Charlie' in name_set:
name_set.remove('Charlie')
name_set.add('Chris')
print("After modifying 'Charlie' to 'Chris':", name_set)
# Delete two names: Let's remove 'Bob' and 'Eva'
name_set.discard('Bob') # discard() won't throw an error if the name doesn't exist
name_set.discard('Eva')
print("After deleting 'Bob' and 'Eva':", name_set)