How do I teach "math equality" vs. "CS assignment" vs. "CS equality logic operator"? Consider the following three uses of equality:


In mathematics, the statement $x = x^2$
In Python, the statement x = x**2
In Python, the expression, x == x**2


The math statement is a constraining assertion restricting x to the set $\{0, 1\}$; the Python assignment always evalutes the right side and assigns to the left side; the Python expression always returns True or False. 

When and how should the differences be pointed out to students? Are there examples producing unexpected results that are especially effective in causing students to abandon the idea that these three meanings of equality are equivalent?
I actually cover this idea in my very first lesson in AP Computer Science, because I have found that students find the different uses of = to be confusing, indeed.  I run a unit based on Tom Roger's unit, Java Ain't Algebra, and I also talk about it a little here.

I do this right at the beginning because, if mutability is not made explicit, students do not seem to exhibit a total loss of comprehension or ability right away, but rather, very slowly slip further and further behind.  They will never be able to articulate what they find confusing about the material, because every piece seems to make sense when looked at in isolation.

The confusion itself stems from simply not realizing that there are articulably different uses of equality in the first place.  In my experience, simply pointing it out is actually enough to stem the tide of the confusion.  (You gave a perfectly wonderful explanation in the question itself.)  Then, two or three more times over the first few weeks of class, I will gently remind them that this equals (some code statement we are examining) is a mutating equals, not the constraining equals of mathematics.

I have not had problems from students in this regard since I began this practice.