在Python中,可以通过字典的键来获取对应的值,并使用print()函数打印出来。可以使用以下方法打印字典的值:
my_dict = {"name": "Alice", "age": 20, "city": "Beijing"}
for key in my_dict:
print(my_dict[key])
输出:
Alice
20
Beijing
my_dict = {"name": "Alice", "age": 20, "city": "Beijing"}
for value in my_dict.values():
print(value)
输出:
Alice
20
Beijing
my_dict = {"name": "Alice", "age": 20, "city": "Beijing"}
for key, value in my_dict.items():
print(value)
输出:
Alice
20
Beijing
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python集合类型有哪些