Proposed PEP for a Conditional Expression
maxm
maxm at normik.dk
Fri Sep 14 10:29:38 EDT 2001
> In Python, one can use the following instead in this case:
>
> outputString = otherString or ""
>
> Personally, I find complicated uses of ?: difficult to scan and
> understand rapidly, contrary to spurious arguments about its supposed
> similarity to English language constructs.
Besides ... what could be simpler than using the fact that booleans in
Python is either 1 or 0:
#################################
>>> a=3
>>> b=4
>>> print ('number two', 'number one')[a < b]
>>> number one
or if you want to get the result of a functionwith only the choosen function
evaluated:
#################################
>>> def n1():
>>> return 'Number one'
>>> def n2():
>>> return 'Number two'
>>> print (n2, n1)[a < b]()
>>> Number one
Any sane Python programmer will grasp those IMMEDIATELY!
;-)
Regards Max M
More information about the Python-list
mailing list