dict = {"a" : "apple", "b" : "banana", "g" : "grape", "o" : "orange"}
我想得到结果
a:apple
dc = {"a" : "apple", "b" : "banana", "g" : "grape", "o" : "orange"}
for k in dc.keys():
print(f'{k}:{dc.get(k)}')
这样的话就把所有的都取了,如果按照索引只取其中指定的一个了?比方说只取索引1
@Matz100: 字典不能按索引查,你可以dict['a']
dict = {"a" : "apple", "b" : "banana", "g" : "grape", "o" : "orange"}
for k, v in dict.items():
print(k, ':', v)