-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path52_Dictionary_Methods.py
61 lines (51 loc) · 1.02 KB
/
52_Dictionary_Methods.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Python Dictionary Methods
print("Python Dictionary Methods:")
# Dictionary Methods
print("\nDictionary Methods:\n")
# clear() method
print("clear() method:")
car = {"brand": "toyota", "model": "X", "year": 1990}
print(car)
car.clear()
print(car)
# copy() method
print("")
print("copy() method:")
d1 = {"brand": "Lenovo", "serial": 123}
d2 = d1.copy()
print(d2)
# fromkeys() method
print("")
print("fromkeys() method:")
a = ('key1', 'key2', 'key3')
b = 0
d3 = dict.fromkeys(a, b)
print(d3)
# get() method
print("")
print("get() method:")
truck = {"brand": "MAN", "model": "X", "year": 2000}
print(truck)
print(truck.get("brand"))
# items() method
print("")
print("items() method:")
print(truck.items())
# keys() method
print("")
print("keys() method:")
print(truck.keys())
# pop() method
print("")
print("pop() method:")
truck.pop("model")
print(truck)
# update() method
print("")
print("update() method:")
truck.update({"color": "green"})
print(truck)
# values() method
print("")
print("values() method:")
print(truck.values())