Implicit conversion to boolean in if and while statements

Albert van der Horst albert at
Mon Jul 16 20:03:56 CEST 2012

In article <50038364$0$29995$c3e8da3$5496439d at>,
Steven D'Aprano  <steve+comp.lang.python at> wrote:
>On Sun, 15 Jul 2012 18:21:06 -0700, Ranting Rick wrote:
>> If HOWEVER we want to "truth test" an object (as in: "if obj") we should
>> be FORCED to use the bool! Why? Because explicit is better than implicit
>And this is why Rick always writes code like:
>integer_value_three = int(1) + int(2)
>assert (int(integer_value_three) == \
>    int(3) is True) is True, str("arithmetic failed")
>list_containing_three_values_which_are_all_integers_but_might_later_have_more_or_fewer_values_or_other_types = list([1, 2, integer_value_three])
>because you can never have too much explicitness. Who wouldn't want
>to read code like that?

Java programmers?

(Couldn't resist ;-) )


Groetjes Albert

Economic growth -- being exponential -- ultimately falters.
albert at spe&ar& &=n

More information about the Python-list mailing list