i ran into something interesting about the python augmented assignment +=
it seems to be automatic data type conversion is not always done for a += b
if a is a 'simpler' data type, while a = a + b
seems to work always
cases where the conversion is done
a = 1
b = 1j
a = 1
b = 0.5
case where the conversion is not done
from numpy import array
a = array([0, 0 ,0])
b = array([0, 0, 1j])
after a += b
, a
remains as integer matrix, instead of complex matrix
i used to think a += b
is the same as a = a + b
, what is the difference of them in the underlying implementation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…