'is not' or '!='

Martin S shieldfire at gmail.com
Tue Aug 19 08:42:34 EDT 2014


2014-08-19 0:04 GMT+02:00 Chris Kaynor <ckaynor at zindagigames.com>:
>
> On Mon, Aug 18, 2014 at 2:42 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>>
>> If you are not dealing with singletons (which is most cases), such as
>> numbers, strings, lists, and most other arbitrary objects, you will need to
>> use "!=" or anytime the two objects you are comparing are not the exact same
>> object, you can easily get the wrong answer.
>
>
> For example, in CPython 3.4.1:
>>>> (254 + 3) is 257
> False
>>>> (254 + 3) == 257
> True
>>>> ('asd' + '@sd') is 'asd at sd'
> False
>>>> ('asd' + '@sd') == 'asd at sd'
> True

Now you have managed to confuse this newbie: What would a valid
"is-example" look like?


Regards,

Martin S



More information about the Python-list mailing list