Boolean idioms (was Re: re Challenge: More Compact?)
Bengt Richter
bokr at accessone.com
Tue Jul 17 01:47:48 EDT 2001
On 16 Jul 2001 06:33:00 -0700, aahz at panix.com (Aahz Maruch) wrote:
>In article <mailman.995247446.16415.python-list at python.org>,
>Tim Peters <tim.one at home.com> wrote:
>>
>>Well, it's un-Pythonic to try to emulate Perl undef via Python None; it's
>>idiomatic to return 0 for false and 1 for true, [...]
>
>I know that it's a frequent Python idiom to use 0/1, but where is it
>specifically un-Pythonic to use None/1?
>--
>>> ['zero','one'][0==1]
'zero'
>>> ['zero','one'][0==0]
'one'
>>> ['zero','one'][None]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: sequence index must be integer
I don't know about Pythonic or not, but maybe a reason, in
case it gets passed symbolically and used raw instead of
as [sym==1]?
Or is it really not dependable even for boolean expressions?
More information about the Python-list
mailing list