sys_conf = {}
sys_conf["type"] = "charts"
sys_conf["client"] = "GWM"
print(sys_conf)
# sys_conf["conf"] error
conf = sys_conf.get("conf", "no conf key in dict")
print(conf) # !
conf = sys_conf.get("conf")
print(conf)
print("test point1")
if not sys_conf.get("conf"):
sys_conf["conf"] = {}
sys_conf["conf"]["sensors"] = {"typeList": ["UFS", "PAS"]}
print(sys_conf)
print("test".center(20, "*"))
for k, v in sys_conf.items():
print(k, v)
print("test".center(20, "*"))
for k in sys_conf.keys():
print(k)
print("test".center(20, "*"))
for v in sys_conf.values():
print(v)
print("test".center(20, "*"))
for k, v in sys_conf.items():
if k == "conf":
print(sys_conf[k]['sensors']['typeList'])
del sys_conf["type"] # attention
print(sys_conf)
car = {
'link': "www.cars.net",
'type': "battery car",
'brand': "tesla",
'mode': "model S",
'color': "red",
'recharge mileage': '500kms',
'price': {
"Area": "China",
"Net": 600000,
"TaxRate": {
"ImportTariffs": 0.1, #
"ValueAdded": 0.08,
"Sale": 0.02
},
"Subside": 20000,
"FinalPrice": 700000
}
}
Basic Python Learning--Dict
最新推荐文章于 2024-11-05 15:28:12 发布