if the else short form

Joost Molenaar j.j.molenaar at gmail.com
Wed Sep 29 07:19:55 EDT 2010


Hi Nico, it's converting fill==True to an int, thereby choosing the
string "False," or "True," by indexing into the tuple.

Try this in an interpreter:
>>> ['a','b'][False]
'a'
>>> ['a','b'][True]
'b'
>>> int(False)
0
>>> int(True)
1


Joost

On 29 September 2010 12:42, Tracubik <affdfsdfdsfsd at b.com> wrote:
>
> Hi all,
> I'm studying PyGTK tutorial and i've found this strange form:
>
> button = gtk.Button(("False,", "True,")[fill==True])
>
> the label of button is True if fill==True, is False otherwise.
>
> i have googled for this form but i haven't found nothing, so can any of
> you pass me any reference/link to this particular if/then/else form?
>
> thanks
> Nico
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list