import pprint
def print_values(key):
pprint.pprint(key, width=1)
我尝试过此操作,但最终同时打印了键和值。我只想让设备打印出值,而不是键。
答案 0 :(得分:0)
最好的方法是...
import pprint
def print_values(key):
pprint.pprint(dictionary[key], width=1)
要仅打印字典的键/值,请执行以下操作:
dictionary = {'abc': 123, 'def': 456, 'ghi': 789}
# print the keys
for entry in dictionary:
print(entry)
# print the values
for entry in dictionary:
print(dictionary[entry])
# print the values
for entry in dictionary.values():
print(entry)