simultaneous assignment

Boris Borcic bborcic at gmail.com
Tue May 2 15:20:48 EDT 2006


Steve R. Hastings wrote:
> So, don't test to see if something is equal to True or False:
> 
> if 0 == False:
>     pass  # never executed; False and 0 do not directly compare

of course they do - ie  isinstance(False,int) is True and False == 0

> 
> 
> You *could* do this, but I don't really recommend it:
> 
> if bool(0) == False:
>     pass  # always executed
> 
> 
> Do this:
> 
> if not 0:
>     pass  # always executed
> 
> if 1:
>     pass  # always executed
> 
> 
> To convert a random value into a boolean value, you could use either
> "bool()" or you could use "not not":
> 
> a = not not 0
> b = bool(0)
> 
> 
> "not not" will work on older versions of Python that didn't have an
> explicit boolean type; "not 0" would return 1 in that case.  "bool()"
> will work in Python 2.2 and newer.



More information about the Python-list mailing list