FW: [Python-Dev] conditional expressions?

Luigi Ballabio ballabio at mac.com
Tue Oct 16 10:24:12 EDT 2001


Hi,

At 02:11 PM 10/16/01 +0200, Markus Schaber wrote:
> > I believe Perl and Ruby has
> >     x = a if b
>
>What does this do? Is it a conditional assignment?

It's a particular case of a syntax not limited to assignments.
Namely,

expression if test
expression unless test

are equivalent to (using Ruby syntax below)

if test
     expression
end

if not test
     expression
end

respectively. I believe the same applies to Perl.
There's no else clause, though---which is a necessary part of the ternary 
operator...

Bye,
         Luigi





More information about the Python-list mailing list