-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary_Ops.py
More file actions
31 lines (24 loc) · 788 Bytes
/
Dictionary_Ops.py
File metadata and controls
31 lines (24 loc) · 788 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
def main():
# Create an initial dictionary
country_capitals = {
"Germany": "Berlin",
"Canada": "Ottawa",
"England": "London"
}
# Accessing values
print("Capital of Germany:", country_capitals["Germany"])
print("Capital of England:", country_capitals["England"])
# Adding an entry
country_capitals["France"] = "Paris"
# Updating an entry
country_capitals["Germany"] = "Bonn"
# Removing an entry
del country_capitals["Canada"]
# Checking key existence
if "France" in country_capitals:
print("France is in the dictionary!")
# Length of the dictionary
num_entries = len(country_capitals)
print("Number of entries in the dictionary:", num_entries)
if __name__ == "__main__":
main()