首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我怎么才能把这个打开?

问我怎么才能把这个打开?
EN

Stack Overflow用户
提问于 2022-07-23 07:11:52
回答 1查看 49关注 0票数 -2

这是数据。我想打开这个元组并打印消息。

代码语言:javascript
复制
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")

“接下来,您想要使用这个列表打印出每个项目的可用位置。

我怎么写这个??

我提供了上述数据。请帮帮忙

​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-23 21:56:59

尝尝这个。

代码语言:javascript
复制
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')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73088749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档