On Wed, Nov 8, 2017 at 4:36 PM, Ali Rıza KELEŞ <ali.r.ke...@gmail.com> wrote:
>> To be more clear here, usually when humans say "identical" they mean having
>> exactly the same value or attributes.
>> Here, Chris means that the two strings are actually the same object rather
>> than two equivalent objects. "is" tests the former (the same object). "=="
>> is for testing the latter (the objects have the same value).
>
> Initially the 'is' compared returned value with None, I changed the
> code and it remained as is. After i have noticed this issue.
>
> Using `is` to compare with None  is OK, isn't it?

Yes, that's correct. None is a singleton, so you check for it by
identity. There are other uses of identity checks, such as:

if str is bytes:
    # we're running Python 2, so encode/decode appropriately

if blah() is NotImplemented:
    # use a fallback

But when you're working with strings or numbers, you'll generally want
to use equality checks.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to