dict_commodity_infos = { 1001: {"name": "屠龙刀", "price": 10000}, 1002: {"name": "倚天剑", "price": 10000}, 1003: {"name": "金箍棒", "price": 52100}, 1004: {"name": "口罩", "price": 20}, 1005: {"name": "酒精", "price": 30}, } 用python打印所有商品信息 格式:商品编号xx,商品名称xx,商品单价xx
时间: 2023-07-31 18:04:21 浏览: 146
你可以使用以下代码来打印所有商品信息:
```python
dict_commodity_infos = {
1001: {"name": "屠龙刀", "price": 10000},
1002: {"name": "倚天剑", "price": 10000},
1003: {"name": "金箍棒", "price": 52100},
1004: {"name": "口罩", "price": 20},
1005: {"name": "酒精", "price": 30},
}
for key, value in dict_commodity_infos.items():
print(f"商品编号{key},商品名称{value['name']},商品单价{value['price']}")
```
这将输出以下结果:
```
商品编号1001,商品名称屠龙刀,商品单价10000
商品编号1002,商品名称倚天剑,商品单价10000
商品编号1003,商品名称金箍棒,商品单价52100
商品编号1004,商品名称口罩,商品单价20
商品编号1005,商品名称酒精,商品单价30
```
阅读全文