-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdic.py
More file actions
41 lines (41 loc) · 768 Bytes
/
dic.py
File metadata and controls
41 lines (41 loc) · 768 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
car = {"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(car["brand"])
print(car)
x = car.keys()
print(x)
#เพิ่มค่าในdic
car["color"] = "white"
print(car)
#แก้ค่าในdic
car["color"] = "red"
print(car)
#การupdate dic
car.update({"light": "blue"})
print(car)
#ลบค่าในdic
car.pop("light")
print(car)
del car["color"]
print(car)
#เพิ่มค่าdicแบบ list
car.update({"part": ["body","wheel","light"]})
print(car)
#เพิ่มค่าdicแบบ Nested dic
myfamily = {
"child1" : {
"name" : "Emil",
"year" : 2004
},
"child2" : {
"name" : "Tobias",
"year" : 2007
},
"child3" : {
"name" : "Linus",
"year" : 2011
}
}
print(myfamily['child3']['year'])