my_dict = {"name": "Alice", "age": 25, "city": "New York"} # 遍历键(keys) for key in my_dict: print(key) # 遍历值(values) for value in my_dict.values(): print(value) # 遍历键值对(items) for key, value in my_dict.items(): print(key, value) #使用enumerate()函数 my_dict = {"name": "Alice", "age": 25, "city": "New York"} for index, key inenumerate(my_dict): value = my_dict[key] print(index, key, value) #使用字典解析 my_dict = {"name": "Alice", "age": 25, "city": "New York"} new_dict = {key: value for key, value in my_dict.items()} print(new_dict)