首页 > 解决方案 > 在 for 循环中打印一个列表,其中的标题连接到每个值

问题描述

for 循环给出了这个错误,ValueError: not enough values to unpack (expected 3, got 1)

for (item,price,quan) in shoplist:
    print('Item:',item, 'Price:$',price, 'Quantity:',quan)

希望它看起来像

商品:牛奶 价格:1.00 美元 数量:4 商品:苹果 价格:1.00 美元 数量:5

标签: pythonpython-3.x

解决方案


推荐阅读