这是数据。我想打开这个元组并打印消息。
shopping_list = [("fruits",'apple','peach'),('dairy','cheese','milk')]
#Use for loop to iterate over list and get each tuple for unpacking
for item in shopping_list:
#unpack the tuple into item and section variables
item1 = fruits
item2 = dairy
#print the message
print("You can find the" "" "in the" fruits "section")“接下来,您想要使用这个列表打印出每个项目的可用位置。
我怎么写这个??
我提供了上述数据。请帮帮忙

发布于 2022-07-23 21:56:59
尝尝这个。
shopping_list = [("fruits",'apple','peach'),('dairy','cheese','milk')]
for item in shopping_list:
section = item[0]
item1 = item[1]
item2 = item[2]
print(f'You can find the "{item1}" "{item2}" in the " {section} "section')https://stackoverflow.com/questions/73088749
复制相似问题