Alex Kleider <aklei...@sonic.net> writes: > Any comments about when/if to use 'if src != None:' vs 'if src is not > None:'?
Express your intention in the code. If you want to express “is this value the ‘None’ singleton?”, compare identity with ‘is’/‘is not’. (This is what you almost always mean when comparing to ‘None’; I know of no useful exceptions to this.) If you want to express “is this value possibly different from ‘None’ but compares as equal?”, compare for equality with ‘==’/‘!=’. (As can be guessed from my description, I don't know of any good reason this would be preferred for ‘None’.) The distinction gets to the issue of object identity, as distinct from value equality. You don't need to know the details of that quite yet. Just know that you can choose whether to allow an object to declare it is equal to some other value, without actually being that same value. That's what you want in most comparisons (use ‘==’), but there is a large minority of comparisons where you instead want to know whether an object *is* some other object (use ‘is’). -- \ “Pinky, are you pondering what I'm pondering?” “Wuh, I think | `\ so, Brain, but how will we get three pink flamingos into one | _o__) pair of Capri pants?” —_Pinky and The Brain_ | Ben Finney _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor