在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