Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Ternary Operator Now?

Reply
Thread Tools

Ternary Operator Now?

 
 
Ben Wilson
Guest
Posts: n/a
 
      02-08-2006
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

 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      02-08-2006
Ben Wilson wrote:
> 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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

 
Reply With Quote
 
 
 
 
Xavier Morel
Guest
Posts: n/a
 
      02-08-2006
Ben Wilson wrote:
> 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.
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      02-08-2006
Steve Holden <(E-Mail Removed)> wrote:
>> x = y if C : else z
>>

>
>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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function call selection using ternary operator marco_segurini C++ 4 09-21-2004 01:37 PM
ternary operator and ostreams Roger Leigh C++ 6 01-19-2004 07:02 PM
Union, ternary operator, Macro, printf don't cooperate for me. Help? Paul E Johnson C Programming 2 10-17-2003 06:41 AM
union, ternary operator, and C. What a mess! Paul E Johnson C Programming 3 10-17-2003 03:44 AM
ternary operator error Jacob Java 12 07-02-2003 07:12 PM



Advertisments