xiaoming_dict = {
"name": "小明",
"age": 18,
"height": 175,
"qq": 12345
}
# 1. 取值 字典["key"]
print(xiaoming_dict["name"])
# 2.增/改
xiaoming_dict["name"] = "xiaom"
print(xiaoming_dict["name"])
xiaoming_dict["phone"] = "111222333"
print(xiaoming_dict["phone"])
# 3. 删
xiaoming_dict.pop("name")
print(xiaoming_dict)
# 4. 循环遍历
for k in xiaoming_dict:
print("%s - %s" % (k, xiaoming_dict[k]))
# 注意k可以格式打印key的名称,
# xiaoming_dict[k]可以打印key对应的值
#与列表联用(结构体数组)
card_list=[
{"name": "zhangsan",
"age": 18,
"height": 175,
"qq": 12345},
{"name": "lisi",
"age": 14,
"height": 170,
"qq": 3456}
]
for card_info in card_list:
print(card_info)