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

cokofreedom at gmail.com cokofreedom at gmail.com
Wed Jan 23 03:58:54 EST 2008


On Jan 23, 9:45 am, Kristian Domke <n... at neither-nor.net> wrote:
> Hello to all
>
> 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
>
> In this case f may be None or a string.
>
> If I am not wrong here, one could simply write
>
> foo = not f
>
> because if f = None:
>
> (not f) = true,
> (true and 1) = true,
> (true or 0) = true
>
> or if f = 'bar'
>
> (not f) = false
> (false and 1) = false
> (false or 0) = false
>
> So why bothering with the longer version?
>
> I hope, I made clear, what I want...
>
> CU
>
> Kristian

f = None
foo = (not f and 1) or 0
# this gives you 1

f = None
foo = not f
# this gives you True




More information about the Python-list mailing list