All of the below is meant to be thoughts/analogies/illustrations to help explain the difference (meant to be said to students) but in reality, this is all dependent on the level of your students.

The expression `x == x**2`

in python is a "test" - is it true, or is it not? Much like when defining a set, you have $\{x|x>2\}$ (i.e., x is only included *iff* $x>2$) - a test to see if something should be included in the set, whereas in python, it is often used to check if something should be done. In this line of reasoning, you could write a program to define a set, expanding on what exactly the mathematical notation means:

```
if x > 2:
list.append(x)
```

In other words, `if x > 2 is True`

then `do list.append(x)`

.

On the other hand, the expression `x = 5`

in python is an "assignment" - this is equal to this, no need for argument. *This is much like in math assigning $x = 5$ or something of the sort. We can later use `x`

to represent 5, much like in an equation $x+5$, given the above definition, we know that the result is $10$, because we are using $x$ to represent $5$. A common analogy is that of the buckets - a bucket has `x`

painted on it and whatever is in the bucket is what `x`

represents.

However, things get more complicated from there - what if `x = x**2`

? Then, you take what `x`

was previously defined as, square it, and then *redefine* `x`

as equal to the new thing. For example, let's "run" the following program:

```
x = 5
print(x)
x = x**2
print(x)
x = x**2
print(x)
```

What will we see? Well, it is quite obvious that the first thing printed is "5"; I doubt there will be much confusion there. Now, the next line is squaring the previous `x`

, i.e., squaring 5 ($5^2$) and then setting that equal to `x`

, so now we basically have the line of code `x = 5**2`

- which produces 25. All very well and good, now we do the same thing - so we basically have `x = 25**2`

or 625.

The difference between those two and what they mean is a very useful and important distinction, but to be honest I think it's not completely unintuitive. Once explained the former is a test and the latter a definition, I think students will catch on fairly quickly with a reminder here and there.

Now we come to your last (well, first) type of equality. $x = x^2$ is a statement of definition, but it can also be manipulated. In python `x = x**2`

is a definition, and it accesses the *previous definition* of `x`

to "solve" it, like we did above. However, to solve $x = x^2$, we move terms around the equals sign - this is a quadratic, so we get $0 = x^2 - x$ and we can factor out the $x$ so $0 = x(x - 1)$ so using the zero product property one gets $x=0$ or $x=1$. We can solve equations like this in Python, but that's not automatically done when you define `x = x**2`

, instead it uses previous definitions.

I hope that conveys what you are wanting, but I really don't think you need to bring up your first definition of equality - the rules of that have been drummed into them from math class, and the new rules of equality appear distinctly enough that I doubt they will be confused.

Now, all of the above is with a nice, good language like Python. *Some* other languages have `=`

, `==`

, and `===`

. I'm not qualified to get into that, but this might not be valid for such craziness.

As for *when* this all should be pointed out - the uses for these concepts are so fundamental, this really is almost day 1 (maybe day 2) of class - install/open the IDE/whatever, learn how to print, then start with variables. This is one of the most important things to learn in a language like python - how to use variables and manipulate them to your advantage.

26They aren't three meanings of "equality". They are three meanings of the

symbol`=`

. Many symbols are used for different meanings, especially in different contexts; this is one of them. For example,`joe@yahoo.com`

and`12 @ $1.25`

mean different things though both use the symbol`@`

. The only problem I can see is if an instructorstartedthe misinterpretation by saying that something like`R = A + B`

is anequationor maybe "this means Ris equal toA + B" and then later corrected that to explain about variables and assignment. – davidbak – 2017-07-02T01:14:47.897It doesn't directly answer your question so I'm putting this as a comment. Read the assignment operator as "becomes equal to". In some programming languages, the := operator is used to disambiguate the symbolism. – pojo-guy – 2017-07-02T12:26:28.983

2By the way the

"The math statement is a constraining assertion restricting x to the set {0,1}"is not accurate. It is correct if we know that x belongs to the set of Integers or the Reals or the Complex numbers. But there are other sets (with a definition of multiplication) where the equation`x=x*x`

has different (less or more) solutions. – ypercubeᵀᴹ – 2017-07-02T21:17:46.310In the R statistical programming language, it's typical to use

`x <- 5`

for assignment, rather than`y = 5`

; and to use`x == y`

for testing equality. – Hatshepsut – 2017-07-02T22:01:59.9302In mathematics, $x=x^2$ is a statement which can be true or false, depending on $x$, quite similarly to your second Python example. – Carsten S – 2017-07-02T22:51:20.493

There is also the

`=`

of Prolog for unification, for even more confusion! – Fatalize – 2017-07-03T06:56:47.720@Fatalize prolog ... /shudder – pojo-guy – 2017-07-03T14:19:15.607

2From the point of view of a mathematics teacher, let me say that the equal sign in mathematics has several, context-dependent meanings. Some students do not appreciate the distinctions. Often they only get them only vaguely, somewhat like the way you know the idiom of your native language. But this may be a side issue to teaching programming, but it's not like students are equipped by their mathematical backgrounds with a clear understanding of the equal sign. They're inclined to think it's always the same, which might be a source of the problem here. – Michael E2 – 2017-07-03T18:53:23.347

@Michael E2 https://scholar.google.com/scholar?q=math+ed+equal+sign wow.

– Bennett Brown – 2017-07-03T19:03:21.3601Here is another one: the equal sign used in a Join clause in SQL. – None – 2017-07-03T20:37:55.103

Note that maths has 2 uses:

`x^2 = y`

and also`let y = 3, then there are 2 solutions`

/`but setting x = 2 we get y = 4`

– Stilez – 2017-07-04T18:58:48.610