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

Kristian Domke news at neither-nor.net
Wed Jan 23 09:45:57 CET 2008


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



More information about the Python-list mailing list