I am confused with Python referencing. Consider the following example:
My task : To edit each element in the list
d = { 'm': [1,2,3] }
m = d['m']
m = m[1:] # m changes its reference to the new sliced list, edits m but not d (I wanted to change d)
Similarly:
d = { 'm': [1,2,3] }
m = d['m']
m = m[0] # As per python referencing, m should be pointing to d['m'] and should have edited d
In python everything goes by reference, then when is a new object created?
Do we always need copy
and deepcopy
from copy
module to make object copies?
Please clarify.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…