Ternary Operator Now?

Discussion in 'Python' started by Ben Wilson, Feb 8, 2006.

  1. Ben Wilson

    Ben Wilson Guest

    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
    Ben Wilson, Feb 8, 2006
    #1
    1. Advertising

  2. Ben Wilson

    Steve Holden Guest

    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/
    Steve Holden, Feb 8, 2006
    #2
    1. Advertising

  3. Ben Wilson

    Xavier Morel Guest

    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.
    Xavier Morel, Feb 8, 2006
    #3
  4. Ben Wilson

    Roy Smith Guest

    Steve Holden <> 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)
    Roy Smith, Feb 8, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacob

    ternary operator error

    Jacob, Jun 30, 2003, in forum: Java
    Replies:
    12
    Views:
    4,732
    pete kirkham
    Jul 2, 2003
  2. Roger Leigh

    ternary operator and ostreams

    Roger Leigh, Jan 16, 2004, in forum: C++
    Replies:
    6
    Views:
    659
    Roger Leigh
    Jan 19, 2004
  3. marco_segurini
    Replies:
    4
    Views:
    803
    Dan Cernat
    Sep 21, 2004
  4. Paul E Johnson

    union, ternary operator, and C. What a mess!

    Paul E Johnson, Oct 17, 2003, in forum: C Programming
    Replies:
    3
    Views:
    461
    Ed Morton
    Oct 17, 2003
  5. Paul E Johnson
    Replies:
    2
    Views:
    575
    Christian Bau
    Oct 17, 2003
Loading...

Share This Page