Trinary operator?

Bengt Richter bokr at oz.net
Thu Apr 25 14:12:29 EDT 2002


On Thu, 25 Apr 2002 10:59:59 -0700, Jeff Shannon <jeff at ccvcorp.com> wrote:

>In article <sepu0okxo8.fsf at pc970145.GermanLloyd.de>, 
>hoel at germanlloyd.org says...
>> Jeff Shannon <jeff at ccvcorp.com> writes:
>> 
>> > ...The only effective difference between 1 and True,=20
>> > and 0 and False, is how it's written, but they add, subtract,=20
>> > multiply, and hash the same.
>> 
>> But there is a difference:
>> 
>> >python
>> Python 2.2.1 (#1, Apr 10 2002, 17:11:02)=20
>> [GCC 3.0.4] on sunos5
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> a =3D 1
>> >>> b =3D 1
>> >>> a is b
>> 1
>> >>> a =3D True
>> >>> a is b
>> 0
>> >>>=20
>
>Yes, True and False are singleton objects that have a different 
>identity than 1 and 0.  The 'is' operator tests object identity.  
>
>>>> a = []
>>>> b = []
>>>> a is b
>0
>>>> 
>
>This doesn't change the fact that a and b are equivalent, and I 
>would still say that there is no effective difference between a 
>and b, here.  Just different object IDs.
>
Another example:
 >>> a=1
 >>> b=1
 >>> a==b, a is b
 (1, 1)
 >>> a=123
 >>> b=123
 >>> a==b, a is b
 (1, 0)

Regards,
Bengt Richter



More information about the Python-list mailing list