How to find difference in years between two dates?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Jul 26 11:07:47 EDT 2006


Roy Smith:
> 2) I find the "and 1 or 0" part very confusing.  I can't remember all the
> minor rules about operator precedence, but I'm sure this works out to some
> clever hack involving boolean short-circuit evaluation to get around the
> lack of a ternary operator in python.  If I need to pull out the reference
> manual to decipher what an expression means, it's too complicated.  Try
> something like:

>From the manual, 5.10:
>(Note that neither and nor or restrict the value and type they return to False and True, but rather return the last evaluated argument. This is sometimes useful, e.g., if s is a string that should be replaced by a default value if it is empty, the expression s or 'foo' yields the desired value. Because not has to invent a value anyway, it does not bother to return a value of the same type as its argument, so e.g., not 'foo' yields False, not ''.)<

Then are such things something good to remove from Python 3.0 (making
or and and always return True or False), to simplify the language, and
make it more clear and reduce the possibility of bugs?

Bye,
bearophile




More information about the Python-list mailing list