>>> d = {}
>>> help(d.fromkeys)
Help on built-in function fromkeys:
fromkeys(...)
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.
The values of all 5 elements are v, and as v is a complex type, it is passed by reference instead of value.
The values of all 5 elements are v, and as v is a complex type, it is passed by reference instead of value.
References, they all point to the same []. . .
Because those lists are the same.
Because
[]
只会被初始化一次,然后所有的key都会引用到它,也就是浅拷贝
, it can be implemented in another way:First way:
in python3
The second type:
copy.deepcopy
I don’t really want to use it anymore