Implicit conversion to boolean in if and while statements

Ethan Furman ethan at stoneleaf.us
Mon Jul 16 16:54:32 EDT 2012


Andrew Berg wrote:
> On 7/15/2012 9:38 PM, Steven D'Aprano wrote:
>>> I would expect None to mean "doesn't exist" or "unknown" or
>>> something like that - e.g., a value of 0 means 0 jelly beans in the jar
>>> and None means there isn't a jar.
 >>
>> How you interpret some_variable = None depends on what some_variable 
>> represents. If some_variable represents "number of jelly beans in a jar", 
>> then that should be 0 if there is no jar.
 >
> What is None supposed to mean then, and what should I do when I have to
> make a distinction between "doesn't exist" and "empty"? Sure, if I need
> to count the total number of jelly beans in all my stores, the
> distinction is meaningless, but if I need to find out which stores sell
> jelly beans so I know which stores need to be restocked, the distinction
> is quite important.

I'm not sure what Steven was trying to say there, but for me:

jar with no jellybeans == 0

no jar == None

~Ethan~



More information about the Python-list mailing list