while true: !!!

gbreed at cix.compulink.co.uk gbreed at cix.compulink.co.uk
Wed Dec 20 07:58:19 EST 2000


In article <3A4024E5.98843CFC at cosc.canterbury.ac.nz>, 
greg at cosc.canterbury.ac.nz (Greg Ewing) wrote:

> The fact that it's taken about three attempts by
> experienced Python people to come up with a full
> and accurate characterisation of what constitute
> 'true' and 'false' in Python suggests that things 
> could have been a lot simpler if there had been a 
> dedicated boolean type!

Ah, but that's because the question was asked the wrong way round.  I hope 
all experienced Pythonistas would know that "" evaluates to false.  
Remembering something is easier than remembering you forgot something.

The general rule is simple: nothing is false.  Take any type, and if 
there's a way of it being nothing, it evaluates false.  So what does no 
string look like? ""  No list?  [].  And so on.  There are some anomolies, 
like [[]] looks like nothing, but such is life.  If you can't think what 
it would mean for an object to be nothing, you have no business using it 
as a boolean.

Adding a boolean type wouldn't make anything simpler.  It would only 
change the question to "What objects x will boolean(x) return false?"  
Restricting falsehood to 0 would make the language simpler, but also less 
powerful.


              Graham



More information about the Python-list mailing list