if the else short form

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Tue Oct 5 07:52:41 CEST 2010

In message 
<e8b46ea8-8d1e-4db9-91ba-501fd1a440e7 at g18g2000yqk.googlegroups.com>, James 
Harris wrote:

> On 29 Sep, 18:20, Seebs <usenet-nos... at seebs.net> wrote:
>> On 2010-09-29, Tracubik <affdfsdfds... at b.com> wrote:
>>> button = gtk.Button(("False,", "True,")[fill==True])
>> Oh, what a nasty idiom.
> I'm surprised you don't like this construct. I hadn't seen it until I
> read the OP's question just now. However, it's meaning was immediately
> apparent.

I’ve used it a lot, from habit because I only started heavily using Python 
with version 2.4.

I’m still not sure I’m comfortable with “<true-part> if <cond> else <false-
part>”, when just about every other language manages to standardize on 
“<cond> ? <true-part> : <false-part>”.

More information about the Python-list mailing list