Trinary operator?
Philipp Lenssen
lenssen at hitnet.rwth-aachen.de
Wed Apr 17 14:30:37 EDT 2002
"Andrew Dalke" <dalke at dalkescientific.com> wrote in message
news:a9kebg$ub9$1 at slb5.atl.mindspring.net...
> Philipp Lenssen:
> >can I use something like
> > verboseGender = (gender == 'm') ? 'male' : 'female'
> >in Python?
>
> No. Search the archives for "ternary operator" for plenty of
> past discussion. Google lists 65 posts for comp.lang.python.
>
Sorry. I actually did search but typed "trinary" instead of "ternary". Since
I didn't know what either word means I got confused, and now that I checked
an online translator to german I'm not even sure the word "trinary" exists.
Oh well.
> Besides, for this specific case you should have some error checking,
> because there are genders other than 'male' and 'female' (eg,
> asexual bacteria and hermaphradite earthworms).
>
> verboseGenderTable = {
> "m": "male",
> "f": "female",
> }
> verboseGender = verboseGenderTable[gender]
>
(I suppose while the bacteria get too frustrated to use my application, the
hermaphrodites are busy playing with themselves.)
More information about the Python-list
mailing list