Ternary Operator Now?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Wilson

    #1

    Ternary Operator Now?

    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

  • Xavier Morel

    #2
    Re: Ternary Operator Now?

    Ben Wilson wrote:[color=blue]
    > 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
    >[/color]
    PEP 308 "Conditiona l Expressions" has been accepted for Python 2.5, I'm
    pretty sure implementation hasn't even started yet.

    Comment

    • Steve Holden

      #3
      Re: Ternary Operator Now?

      Ben Wilson wrote:[color=blue]
      > 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
      >[/color]

      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/

      Comment

      • Roy Smith

        #4
        Re: Ternary Operator Now?

        Steve Holden <steve@holdenwe b.com> wrote:[color=blue][color=green]
        >> x = y if C : else z
        >>[/color]
        >
        >Currently scheduled for next (2.5) release, but not yet implemented.[/color]

        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)

        Comment

        Working...