如何从列表中的字典中仅打印一个项目 [英] How can I print only one item from dictionary in list
本文介绍了如何从列表中的字典中仅打印一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么才能只打印一个项目,例如我只需打印'data1'
这里是代码:
test_list = [{'data1':1,data2:2,data3:3}]
for test_list中的项目:
打印(项目)
我尝试过什么:
i搜索了我无法找到的所有内容:(
解决方案
为什么不使用例如
test_list = {' data1' : 1 , data2: 2 , data3 : 3 }
print (test_list [' data1'])
how can i print only one item for example i need to print only 'data1'
here is code:
test_list = [{'data1':1,"data2":2,"data3":3}]
for item in test_list:
print(item)
What I have tried:
i searched everything nothing i can find :(
解决方案
Why not use a dictionary. For example
test_list = {'data1':1,"data2":2,"data3":3} print(test_list['data1'])
这篇关于如何从列表中的字典中仅打印一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文