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
On Jan 23, 9:45 am, Kristian Domke [EMAIL PROTECTED] 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.
Kristian Domke 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
Gary Herron napisaĆ(a):
However there *is* a (subtle) difference between
not f
and
(not f and 1) or 0
The first produces a boolean value, and the second produces an int
value, but since one is a subclass of the other, you'd have to write
quite perverse code care about the
Sorry, posted to quickly.
Yes your logic is correct about the logic of the return, but theirs
actually differs in what it returns, and I am guessing it is an
important change. Where is this foo used? Perhaps its value is used
in a way a boolean return couldn't be?
Just a note, with these kind of
Kristian Domke [EMAIL PROTECTED] wrote:
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
Yes, it sounds pretty silly, and not just on the level you spotted.
The only difference between the two expressions is
I am surprised nobody pointed out explicitely that
True==1 and False==0
so that for instance
5*(True+True)==10
and even (but implementation-dependent) :
5*(True+True) is 10
BB
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 23 Jan 2008 09:30:28 +, Duncan Booth wrote:
Kristian Domke [EMAIL PROTECTED] wrote:
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
Yes, it sounds pretty silly, and not just on the level you
Boris Borcic wrote:
I am surprised nobody pointed out explicitely that
True==1 and False==0
Several of us did indeed point this out by saying that bool's are a
subclass of ints.
so that for instance
5*(True+True)==10
and even (but implementation-dependent) :
5*(True+True) is 10
BB
Steven D'Aprano [EMAIL PROTECTED] wrote:
On Wed, 23 Jan 2008 09:30:28 +, Duncan Booth wrote:
Kristian Domke [EMAIL PROTECTED] wrote:
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
Yes, it sounds
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
On Jan 23, 4:06 am, Gary Herron [EMAIL PROTECTED] wrote:
However there *is* a (subtle) difference between
not f
and
(not f and 1) or 0
The first produces a boolean value, and the second produces an int
value, but since one is a subclass of the other, you'd have to write
quite perverse
12 matches
Mail list logo