Test 0 and false since false is 0

Paul D. DeRocco pderocco at ix.netcom.com
Fri Jul 7 00:37:09 EDT 2017


> From: Dan Sommers
> 
> > On Thu, 06 Jul 2017 19:29:00 -0700, Sayth Renshaw wrote:
> > 
> > I have tried or conditions of v == False etc but then the 0's being
> > false also aren't moved. How can you check this at once?
> 
> Maybe this will help:
> 
>     Python 3.5.3+ (default, Jun  7 2017, 23:23:48) 
>     [GCC 6.3.0 20170516] on linux
>     Type "help", "copyright", "credits" or "license" for more 
> information.
>     >>> False == 0
>     True
>     >>> False is 0
>     False

Funny how the subject line inadvertently prefigures the answer: False
*isn't* 0. False *equals* 0. So just change "==" to "is" and "!=" to "is
not" and it should work.

Also, it can be done in a single expression, with no local variables.

-- 

Ciao,               Paul D. DeRocco
Paul                mailto:pderocco at ix.netcom.com




More information about the Python-list mailing list