字典的运算 可变数据类型

1、get  获取值

s_info ={
"m":{ "lots":1,
"max_lot":1024,
"step":0.18 ,
"p_id":"m"

},
"a": {"lots": 1 ,
"max_lot": 1024 ,
"step": 0.28 ,
"p_id": "a"

}
}
print(s_info["a"]["p_id"])
print(s_info.get("m","123"))
print(s_info["a"].get("p_id"))
print(s_info.get("m").get("p_id"))
2、更新值 update
s_info.update({"l":9})
print(s_info)
s_info["a"].update({"lots":62})
print(s_info["a"])
s_info["m"]["保证金"] = 6000
print(s_info["m"])
3、pop 删除值
print(s_info["m"].pop("保证金"))
print(s_info["m"])
4、clear
s_info["a"].clear()
print(s_info)
5 for 循环
for key in s_info.keys():
print(key)
6、key and values
for k in s_info["m"].values():
print(k)
7。 item
for v in s_info["m"].items():
print(v)
for h,v in s_info["m"].items():
print(h,v)
for j in list(s_info):
if j=="a":
s_info.pop('a')
print(list(s_info))

集合
trade ={1,2,3,4,5,6}
a_trader={1,2,3}
new_trade =trade -a_trader // 求集合差集
print(new_trade)

for ta in new_trade:
print(ta)
a_trader.add(ta)
print(a_trader) // 集合合

nan
代表任意值
m = float('nan')    
print(m+5) nan 不与自身相等, 返回false


posted on 2022-03-20 21:18  Lionever  阅读(22)  评论(0编辑  收藏  举报