Ternary Operator Now?

B

Ben Wilson

I read somewhere else that Python was getting a ternary operator (e.g.
x = (true/false) ? y : z). I read the PEP about it and that the PEP had
been approved this past Fall. Has this been released into the wild yet?

IIRC, the operator is like:

x = y if C : else z
 
S

Steve Holden

Ben said:
I read somewhere else that Python was getting a ternary operator (e.g.
x = (true/false) ? y : z). I read the PEP about it and that the PEP had
been approved this past Fall. Has this been released into the wild yet?

IIRC, the operator is like:

x = y if C : else z

Currently scheduled for next (2.5) release, but not yet implemented.

There's no colon in the construct.

regards
Steve
 
X

Xavier Morel

Ben said:
I read somewhere else that Python was getting a ternary operator (e.g.
x = (true/false) ? y : z). I read the PEP about it and that the PEP had
been approved this past Fall. Has this been released into the wild yet?

IIRC, the operator is like:

x = y if C : else z
PEP 308 "Conditional Expressions" has been accepted for Python 2.5, I'm
pretty sure implementation hasn't even started yet.
 
R

Roy Smith

Steve Holden said:
Currently scheduled for next (2.5) release, but not yet implemented.

This still makes me barf. Has Python jumped the shark?

It looks marginally better if you write it as:

x = (y if C else z)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top