How to access my dictionary
This question already has an answer here:
Discover
is a key of your dictionary. You can access the keys collection in your dictionary using keys() method. Then use each key to access the associated element.
for key in account.keys():
print(key)
print(account[key])
Since Discover
is the only key you could do print account.keys()[0]
.
But if you ever had more keys this won't work every time since dictionaries are arbitrarily ordered (in other words, have no sense of order), you will need to iterate over the keys()
list, or simply print account.keys()
to print the whole keys list.
如果你有更多的键,你可以像这样循环:
for i in account:
print i
链接地址: http://www.djcxy.com/p/30362.html
上一篇: 在Python中迭代字典
下一篇: 如何访问我的字典