Ternery operator
Uwe Schmitt
uwe.schmitt at procoders.net
Mon Sep 8 08:10:12 EDT 2003
Andrew Chalk <achalk at xxxmagnacartasoftware.com> wrote:
> Is there a python equivalent of the C ternery operator?
> I.e.:
> fred = (x == 1) ? 12 : 15
> If not, what's the best way to construct the same logic?
fred = ( x==1 and [12] or [15])[0]
or
fred = [ 12, 15] [not x==1]
Further hints / explanations
at http://www.procoders.net/tutorials/boolean
Greetings, Uwe.
--
Dr. rer. nat. Uwe Schmitt http://www.procoders.net
schmitt at procoders.net "A service to open source is a service to mankind."
More information about the Python-list
mailing list