Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

Steven Bethard steven.bethard at gmail.com
Wed Jan 23 14:06:19 EST 2008


Kristian Domke wrote:
> I am trying to learn python at the moment studying an example program
> (cftp.py from the twisted framework, if you want to know)
> 
> There I found a line
> 
> foo = (not f and 1) or 0

Equivalent to ``foo = int(not f)``

> In this case f may be None or a string.
> 
> If I am not wrong here, one could simply write
> 
> foo = not f

No cast to int() here.

STeVe



More information about the Python-list mailing list