-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
41 lines (31 loc) · 740 Bytes
/
Copy pathdictionary.py
File metadata and controls
41 lines (31 loc) · 740 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
#dictionary in python is an unordered, mutable collection of key value pairs
#dictionary example
student = {
"name": "Antonio",
"age": 24,
"country": "South Africa"
}
#accessing dictionary values
print(student["name"])
print(student["age"])
print(student["country"])
#dictionary is mutable(can change)
#update a value
student["age"] = 25
#dictionary manipution
#add a new key
student["course"] = "Python"
#remove the key
student.pop("age")
#remove the last inserted item
student.popitem()
#delete the key
del student["country"]
#clear dictionary
student.clear()
#dictionary methods
print(student.keys())
print(student.values())
print(student.items())
#update multiple values
student.update({"name": "race", "age": 30})