在Python中,可以使用print()函数来打印字典。例如:
my_dict = {'name': 'Tom', 'age': 18, 'city': 'New York'} print(my_dict) 输出结果为:
{'name': 'Tom', 'age': 18, 'city': 'New York'} 如果想要更美观的输出格式,可以使用json.dumps()函数,需要先导入json模块:
import json my_dict = {'name': 'Tom', 'age': 18, 'city': 'New York'} print(json.dumps(my_dict, indent=4)) 输出结果为:
{ "name": "Tom", "age": 18, "city": "New York" }