>>> (()) == ()
True
>>> (())
()
The equals() method compares two strings, and returns true if the strings are equal, and false if not.
We can use == operators for reference comparison (address comparison) and . equals() method for content comparison. In simple words, == checks if both objects point to the same memory location whereas . equals() evaluates to the comparison of values in the objects.
The major difference between the == operator and . equals() method is that one is an operator, and the other is the method. Both these == operators and equals() are used to compare objects to mark equality.
The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
()
is a 0-tuple. (foo)
results in the value of foo
. Hence, (())
results in a 0-tuple.
From the tutorial:
; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses).
For the same reason that (4) == 4
: adding parentheses around an expression does not alter its meaning (unless it would otherwise have been grouped differently of course).
Note that ( foo )
is not a 1-tuple. Otherwise things like 3 * (4 + 5)
would be an error as (4 + 5)
would be a 1-tuple containing 9 and you can't add a number to a 1-tuple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With