[Flask] Shouldn't is and == operator work same way while doing string comparisons?
Cameron Simpson
cs at cskk.id.au
Fri May 3 19:29:58 EDT 2019
On 04May2019 00:41, Arup Rakshit <ar at zeit.io> wrote:
>I tested the both while in REPL.
Testing only tells you what happens in your test, with a aprticular
environment. It doesn't inform you about the language specification,
except in so far as a failed test might tell you that your assumption
was incorrect.
>They work same, why it is then different then flask app code?
Python interning small strings is an implementation detail, not part of
the language specification. So there is no explicit guarantee that 2
strings with the same value are the same string object, even for small
strings.
If you want to act on the value of something, use ==. Using "is" is NOT
FOR THAT. It is to check if 2 object references refer to the same
object. This is rarely what you want; it is most useful with singletons
such as sentinels.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Flask
mailing list