Conditional operator in Python?

Sheila King sheila at spamcop.net
Mon Apr 2 11:02:07 EDT 2001


On Mon, 2 Apr 2001 10:27:37 +0000 (UTC), duncan at rcp.co.uk (Duncan Booth) wrote
in comp.lang.python in article <Xns907772F534CFAduncanrcpcouk at 127.0.0.1>:

:
:Please don't do this, as it doesn't do what you think.
:
:>>> a = 0
:>>> b = -5
:>>> (a > b) and a or b
:-5
:
:and consider that one of the common uses for a max function is to set a 
:lower bound of 0 on a calculation.

The reference I sited in the post you are replying to:
http://diveintopython.org/apihelper_andor.html

goes over that difficulty and how to get around it.

Still, I personally wouldn't use this method. if-else seems fine to me?

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list