**
本文章将不断更新
**
方法一:使用键循环,并根据键循环,获取值
dic_test = {"name": "lzy", "high": 1.8, "weight": 128}
for k in dic_test:
print("键为:{},值为:{}".format(k, dic_test[k]))
# 结果
键为:name,值为:lzy
键为:high,值为:1.8
键为:weight,值为:128
方法二:使用items方法,直接获取键和值
dic_test = {"name": "lzy", "high": 1.8, "weight": 128}
for k, v in dic_test.items():
print("键为:{},值为:{}".format(k, v))
# 结果
键为:name,值为:lzy
键为:high,值为:1.8
键为:weight,值为:128
方法三:使用values方法,只获取值
dic_test = {"name": "lzy", "high": 1.8, "weight": 128}
for v in dic_test.values():
print("值为:{}".format(v))
# 结果
值为:lzy
值为:1.8
值为:128