Adding new math operators

Alex Martelli alex at magenta.com
Thu Aug 3 10:12:30 EDT 2000


"Huaiyu Zhu" <huaiyu_zhu at yahoo.com> wrote in message
news:Pine.LNX.4.10.10008030247030.3900-100000 at localhost.localdomain...
    [snip]
> 3. Bitwise operation (regarding integer as collection of bits)
>
>    2 and 3  ===> 1
>    2 ~and 3 ===> 2
>    2 or 3   ===> 1
>    2 ~or 3  ===> 3

Python's current semantic for and/or is different:

>>> print 2 and 3
3
>>> print 2 or 3
2

ie., x and y -> y if x evaluates to true, else x
x or y -> x if x evaluates to true, else y

Having 'x and y' return 0 or 1 would badly
impoverish this very useful behavior.


Otherwise, quite well-argued IMHO.


Alex







More information about the Python-list mailing list