题目:Provided is a list of data about a store’s inventory where each item in the list represents the name of an item, how much is in stock, and how much it costs. Print out each item in the list with the same formatting, using the .format method (not string concatenation). For example, the first print statment should read The store has 12 shoes, each for 29.99 USD.
inventory = ["shoes, 12, 29.99", "shirts, 20, 9.99", "sweatpants, 25, 15.00", "scarves, 13, 7.75"]
for item in inventory:
item = item.split(',')
print('The store has{item[1]} {item[0]}, each for{item[2]} USD.'.format(item = item))

该博客介绍了如何使用Python 3的`.format`方法来格式化输出商店库存信息,包括商品名称、库存数量和单价。示例展示了如何正确地打印出库存列表,以统一的格式展示每个商品。
722

被折叠的 条评论
为什么被折叠?



