【发布时间】:2015-08-02 10:50:02
【问题描述】:
我正试图让我的程序从字典中打印出"banana"。最简单的方法是什么?
这是我的字典:
prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3
}
【问题讨论】:
-
您要按字面意思打印单词“banana”还是与“banana”关联的值(在本例中为 4)?
-
to print out banana with a FOR loop, so when I run it, each key would also be printed out你的意思是for k in prices: print k?这将打印出字典中的所有键。 -
至第一条评论:在 python 3.6+ 中,字典是有序的(参见stackoverflow.com/questions/39980323/…)
标签: python dictionary