None or 0

Jay O'Connor joconnor at
Sat Sep 7 18:43:05 CEST 2002

On Sat, 07 Sep 2002 09:08:08 -0700, John Baxter <jwbaxter at>

>In article <k7ip4-0p3.ln1 at>,
> Michael Stroder <michael at> wrote:
>>  >>> repr(0 or None)
>> 'None'
>>  >>> repr(None or 0)
>> '0'
>>  >>> repr('' or None)
>> 'None'
>>  >>> repr(None or '')
>> "''"
>>  >>>
>> Is it guaranteed to work like this or should that be avoided?
>It seems very convenient to implement or (and and) by returning the 
>first object which decides the answer.

I noticed that happening.  It seems sensible for short-circuiting
that in an "or", you just return th second term , regardless of what
it is

>My guess is that enough people are counting on the behavior that even if 
>the underlying hardware or implementation language were to shift enough 
>to make this implementation quite inconvenient, it would nonetheless 
>Having said that, I tend not to like counting on it, because it 
>stretches the extra-Python definition of the operators quite a bit.  
>Particularly on the "and" side:
>>>> print 5 and 1
>Go into (English-speaking) classrooms, and you're going to hear chants 
>of "5 and 1 is 6" not "5 and 1 is 1".

Because in that contexts "and" means "plus" and in this context "and"
means "logical and"

Take care,

Jay O'Connor
joconnor at

"God himself plays on the bass strings first, when he tunes the soul"

More information about the Python-list mailing list