[Tutor] While truth

Cameron Simpson cs at zip.com.au
Tue May 20 12:00:12 CEST 2014


On 20May2014 08:25, Ian D <duxbuz at hotmail.com> wrote:
>I was reading a tutorial that had these examples in it:
>
>>>> while False:
>  print("False is the new True.")
>
>>>> while 6:
>  print("Which numbers are True?")
>
>while -1:
>  print("Which numbers are True?")
>
>while 0:
>  print("Which numbers are True?")
>
>Unfortunately the author never explained these statements.

That is a pity. Sounds badly written.

I would imagine the intent is that you could try these and see what happens. I 
think that exercise would be more effective with if-statements instead of 
while-statements.

Basicly, the point is likely to show that you do not need to use a "bool" as 
the while condition; any value considered "truthy" by Python will do if it 
matches what you are working with.

Broadly, None and 0 and False and "empty" collections (empty lists, empty sets, 
zero length strings, etc) are "false", and most other things are "true".

Cheers,
Cameron Simpson <cs at zip.com.au>

Rugby is a beastly game played by gentlemen; soccer is a gentleman's game
played by beasts; football is a beastly game played by beasts.
- Henry Blaha


More information about the Tutor mailing list