effbot at telia.com
Sun Apr 9 12:35:09 EDT 2000
Oleg Broytmann wrote:
> On Sun, 9 Apr 2000, Robert W. Cunningham wrote:
> > blah = (((test and [true]) or [false])) # blah = (test ?
> > true : false)
> > Works for me! Only if I have a good reason to suspect a problem in this
> > particular line of code will I have to look past the comment.
> There is no problem in this particular line, but you'll have plenty of
> them if you'd try to use this paradigm:
> blah = ((foo() and [poo()]) or [boo()])
> In C, "foo() ? poo() : boo()" will not call boo() if foo() returns
> but in Python, you'll have a side-effect of calling boo() even if foo()
> returns true - what is wrong, usually.
did you try running the code?
python's "and" and "or" operators doesn't evaluate the
second argument unless they really have to...
More information about the Python-list