True inconsistency in Python
Alex Martelli
aleax at aleax.it
Thu Nov 13 08:49:17 EST 2003
Borcis wrote:
> Scott Chapman wrote:
>
>>
>> if var == True: # only works if var is 1
>> blah
>>
>> ' Must use:
>>
>> if var: # works if var is not 0
>> blah
>
> there's the equivalent, and more explicit :
>
> if bool(var)==True : blah
Why stop there? If adding one useless and redundant check is
better, surely having more will be merrier and merrier...:
if ( bool(var) == True) == True: doubleblah
oh wait, we should add ANOTHER level of uselessness...:
if (( bool(var) == True) == True) == True: tripleblah
oh wait...
"if var:" is the Pythonic way. You could argue that each
level of "== True" makes it ``more explicit'', but I just
consider them all equally silly in their utter redundancy.
[[ we TOLD Guido people would start on this absurd path, when
he added bool, True, and False, but he wouldn't listen...
]]
Alex
More information about the Python-list
mailing list