Top "Equality" questions

Equality is a relationship between two or more items or variables or objects that exists if (1) the items are the same item, variable, or object or (2) the items are different items, variables or objects but they have the same value.

How do I compare strings in Java?

I've been using the == operator in my program to compare all my strings so far. However, I ran into a …

java string equality
Which equals operator (== vs ===) should be used in JavaScript comparisons?

I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals …

javascript operators equality equality-operator identity-operator
Why does comparing strings using either '==' or 'is' sometimes produce a different result?

I've got a Python program where two variables are set to the value 'public'. In a conditional expression I have …

python string comparison identity equality
String comparison in Python: is vs. ==

I noticed a Python script I was writing was acting squirrelly, and traced it to an infinite loop, where the …

python string comparison equality
What is the difference between == and equals() in Java?

I wanted to clarify if I understand this correctly: == is a reference comparison, i.e. both objects point to the …

java identity equality object-comparison
Is there a difference between "==" and "is"?

My Google-fu has failed me. In Python, are the following two tests for equality equivalent? n = 5 # Test one. if n == 5: …

python reference equality semantics
Is False == 0 and True == 1 an implementation detail or is it guaranteed by the language?

Is it guaranteed that False == 0 and True == 1, in Python (assuming that they are not reassigned by the user)? For instance, …

python boolean equality language-specifications
Compare object instances for equality by their attributes

I have a class MyClass, which contains two member variables foo and bar: class MyClass: def __init__(self, foo, bar): …

python equality
Elegant ways to support equivalence ("equality") in Python classes

When writing custom classes it is often important to allow equivalence by means of the == and != operators. In Python, this …

python equality equivalence
Python if not == vs if !=

What is the difference between these two lines of code: if not x == 'val': and if x != 'val': Is one …

python if-statement equality