The ==
and !=
operators in Java works differently for different kinds of values: for
primitives, they check whether the two values represent the same meaning, but for objects they checks whether the
values occupy the same location in memory. Therefore, given two objects x
and y
that
hold the same data but have different places in memory, the Java expression x == y
will be false. To
check for semantic equality, the programmer must invoke a dedicated method, usually by writing an expression like
x.equals(y)
.
In contrast, Python's ==
and !=
operators always check whether two values mean the same
thing and ignore their locations in memory. If a Python programmer wants to compare memory locations, they must
instead use the operators is
and is not
. For example, given the x
and
y
from above, Python would interpret x == y
as true, but x is y
as false.
Sometimes the two kinds of operators effectively have the same meaning. For instance, the only way for two
enumeration values to have the same meaning is if they have the same memory location. In such cases, it is
considered good style to prefer is
and is not
over ==
and
!=
.
Finish the program by writing relational operators so that it correctly labels each of the claims as true or false.