I was thinking why the '=' in '+=' is considered as assignment while '=' in '>=' is not considered as such. There is no importance behind this question but some random thought of a beginner. For example purpose, you can consider that
a = np.array([1,2,3,4,5])
a += 2 # array updated and assigned to a
a>=2 # becomes a boolean indexing filter
a += 2
changes the value of a
. It reassigns it's value to be two more than it was before. By the way, +=
as a whole is the assignment operator, not just the =
.
a>=2
does not change the value of a
. Yes, it becomes true or false. But 'true' or 'false' is all it is. It does not get assigned to anything. The value of a
is as it was before.
You can do b = a>=2
. But in that case, =
is the assignment operator because it is what assigns the value to b.