python - 是否可以将变量分配为字典中的值(对于 Python)?
问题描述
对于字典'dict1'中的变量'a'和'b',以后是否可以使用'dict1'中给出的键调用变量'a'来为其赋值?
a=""
b=""
dict1= {0:a,1:b}
dict1[0] = "Hai" #assign a value to the variable using the key
print(a) #later call the variable```
解决方案
不,当您进行赋值 {key:value} 时,该值不会引用原始变量,因此改变其中一个不会影响另一个。