What is the difference between python and java == operator - Stack Overflow
What language is more advantageous, Java or Python?
What are the main differences between Python and Java?
Main differences between Python and Java
Videos
Python's str class uses value-equality for its __eq__ method. In Python, classes can override __eq__ to define how == behaves.
Contrast that with Java where == always does reference-equality. In Java, == will only return true if both objects are literally the same object; regardless of their content. Java's == is more comparable to Python's is operator.
A better comparison, as noted in the comments, would be to compare these:
"a".equals("a") // Java
"a" == "a" # Python
Java's String class has its equals do a value equality instead of of reference equality.
In python == is used to compare the content of the objects by overriding the operator.eq(a, b) method, str class has overridden this in order to compare the content of objects
These are the so-called “rich comparison” methods. The correspondence
between operator symbols and method names is as follows: x<y calls
x.__lt__(y), x<=y calls x.__le__(y), x==y calls x.__eq__(y), x!=y calls
x.__ne__(y), x>y calls x.__gt__(y), and x>=y calls x.__ge__(y).
But in java == operator is used compare the reference of objects here
Using the “==” operator for comparing text values is one of the most common mistakes Java beginners make. This is incorrect because “==” only checks the referential equality of two Strings, meaning if they reference the same object or not.
so in java to compare the content of object you have to use equals which is overridden in String class.
if (str1.equals(str2))
so java == operator is equal to is operator in python which compare both references are pointed to same object or not
What language is more advantageous, Java or Python? What do you think?