Break and Continue: While Loops

Jon Ribbens jon+usenet at unequivocal.co.uk
Thu Jun 23 07:57:52 EDT 2016


On 2016-06-23, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Jun 23, 2016 at 8:15 PM, BartC <bc at freeuk.com> wrote:
>> Actually pretty much any expression can be used, because Python can
>> interpret almost anything as either True or False. Don't ask for the rules
>> because they can be complicated, but for example, zero is False, and any
>> other number is True. I think.
>
> The rules are very simple. Anything that represents "something" is
> true, and anything that represents "nothing" is false. An empty
> string, an empty list, an empty set, and the special "None" object
> (generally representing the absence of some other object) are all
> false. A string with something in it (eg "Hello"), a list with
> something in it (eg [1,2,4,8]), etc, etc, are all true.

Exactly. This is a major everyday strength of Python in my view.

I seem to recall that Java originally insisted that only booleans
(excluding even Booleans, which are a different thing because of
course they are) could be checked for truth and it was one of
Java's significant warts.



More information about the Python-list mailing list