要修改字典中的value值,可以通过以下几种方式:
示例代码:
my_dict = {'key1': 'value1', 'key2': 'value2'}
my_dict['key1'] = 'new value1'
print(my_dict) # 输出: {'key1': 'new value1', 'key2': 'value2'}
示例代码:
my_dict = {'key1': 'value1', 'key2': 'value2'}
my_dict.update({'key1': 'new value1', 'key2': 'new value2'})
print(my_dict) # 输出: {'key1': 'new value1', 'key2': 'new value2'}
示例代码:
my_dict = {'key1': 'value1', 'key2': 'value2'}
new_dict = {key: 'new ' + value for key, value in my_dict.items()}
print(new_dict) # 输出: {'key1': 'new value1', 'key2': 'new value2'}
请根据具体需求选择适合的方法来修改字典的value值。