Re: Is vs Equality Operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry Reedy

    Re: Is vs Equality Operator


    "Good Z" <goodz158@yahoo .comwrote in message
    news:706397.160 40.qm@web35903. mail.mud.yahoo. com...
    | Hello,
    | I am having problem in using is. Here is what i am doing.
    |
    | x=''
    | if x is None or x is '':
    | return 1

    x is not the singleton value None, nor is it the newly created null string
    object. It is up to the implementation whether each instance of '' reuses
    one cached (or interned) null string object or creates another. Don't
    depend on such behavior unless you really mean it. Same goes for comparing
    ints.

    |
    | The above statement does not return value 1.
    |
    | If i changed the above check to
    | if x == None or x == '':
    | return 1
    | Now it works fine.

    x still is not None but does equal in value ''

    I recommend here

    if x is None or x == '': ...

    tjr



Working...