这是我的密码:
everyday = {'hello':[],'goodbye':{}}
i_want = everyday
i_want ['afternoon'] = 'sun'
i_want['hello'].append((1,2,3,4))
print(everyday)
我想得到这个:
i_want = {'afternoon': 'sun', 'hello': [(1, 2, 3, 4)], 'goodbye': {}}
everyday = {'hello':[],'goodbye':{}}
但我得到:
i_want = {'afternoon': 'sun', 'hello': [(1, 2, 3, 4)], 'goodbye': {}}
everyday = {'afternoon': 'sun', 'hello': [(1, 2, 3, 4)], 'goodbye': {}}
如果不修改“每日”字典,我怎样才能得到我想要的?你知道吗
改变一下:
所发生的是调用(i\u want=everyday)实际上是创建了一个对everyday的引用
如果您想查看是否引用了词典,只需调用
下面的工作与marc的答案类似,但不是创建一个新的列表然后追加,而是在创建列表的同时执行。你知道吗
输出:
只需添加第二个print语句即可获得所需的输出。你知道吗
相关问题 更多 >
编程相关推荐